Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Getting errors when compiling the code to assembly language (gcc -S testcode.c)

ID: 3640140 • Letter: G

Question

Getting errors when compiling the code to assembly language (gcc -S testcode.c) :

testcode.c: In function `main':
testcode.c:21: error: missing terminating " character
testcode.c:22: error: `Extract' undeclared (first use in this function)
testcode.c:22: error: (Each undeclared identifier is reported only once
testcode.c:22: error: for each function it appears in.)
testcode.c:22: error: parse error before "a"
testcode.c:22: error: stray '' in program
testcode.c:22: error: stray '' in program
testcode.c:23: error: stray '' in program
testcode.c:23: error: missing terminating " character
testcode.c:3: warning: return type of 'main' is not `int'


Code:

#include
void main()
{
char e,d;
int a[32],b,i,c=31;
printf("Please enter in a number between [0-4096]: User input: ");
scanf("%d",&b);
for(i=0;i<32;i++)
{
a[i]=0;
}
while(b!=0)
{
a[c]=b%2;
c--;
b=b/2;
}
c=31;
while(1)
{
printf(" Please select one of the following functions: e : Extract a particular bit s : Set a particular bit q : Quit this program ");
fflush(stdin);
scanf("%c",&d);
fflush(stdin);
if(d=='e')
{
printf("Please enter in the bit position to extract [0-31]:");
scanf("%d",&e);
printf("The initial value in binary is: ");
for(i=0;i<32;i++)
{
printf("%d",a[i]);
}
printf(" The bit value in position %d is %d ",e,a[31-e]);
}
else if(d=='s')
{
printf(" Please enter in the bit position to set [0-31]:");
scanf("%d",&e);
a[31-e]=1;
printf("The resulting value in binary is: ");
for(i=0;i<32;i++)
{
printf("%d",a[i]);
}
}
else if(d=='q')
{
break;
}
else printf("Wrong choice, enter again: ");
}
}

Explanation / Answer

The error has been corrected.

It was due to the printf() statement in line 22 being long which is actually not a problem but if not copied properly from here to the c editor will not work.

Anyways it has been corrected and will have no further issues....:)..

#include<stdio.h>
void main()
{
char e,d;
int a[32],b,i,c=31;
printf("Please enter in a number between [0-4096]: User input: ");
scanf("%d",&b);
for(i=0;i<32;i++)
{
a[i]=0;
}
while(b!=0)
{
a[c]=b%2;
c--;
b=b/2;
}
c=31;
while(1)
{
printf(" Please select one of the following functions: ");

printf("e : Extract a particular bit s : Set a particular bit");

printf(" q : Quit this program ");
fflush(stdin);
scanf("%c",&d);
fflush(stdin);
if(d=='e')
{
printf("Please enter in the bit position to extract [0-31]:");
scanf("%d",&e);
printf("The initial value in binary is: ");
for(i=0;i<32;i++)
{
printf("%d",a[i]);
}
printf(" The bit value in position %d is %d ",e,a[31-e]);
}
else if(d=='s')
{
printf(" Please enter in the bit position to set [0-31]:");
scanf("%d",&e);
a[31-e]=1;
printf("The resulting value in binary is: ");
for(i=0;i<32;i++)
{
printf("%d",a[i]);
}
}
else if(d=='q')
{
break;
}
else printf("Wrong choice, enter again: ");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote