Please help me to check my coding where the mistake is and correct it for me. Thank you for the help. I need c programming coding only.
Question:
Write down a function getint() , which would receive a numeric string from the keyboard, convert it to an integer number and return the integer to the calling function. A sample usage of getint() is shown below:
My answer:Code:#include <stdio.h> int main () ( int a; a=getint(); printf(“you entered %d\n”, a); return 0; }
Code:#include <stdio.h> #include<string.h> #define num 50 void getint() { int i,j; char cha1[50]; char cha2[num][50]; printf ("Please enter the number:(Enter 'endtext' when finish.)\n"); scanf ("%s",&cha1); printf ("1"); while (strcmp(cha1, "endtext")!=0) { cha2[i]=cha1; i++; scanf ("%s",&cha1); } for (j=0;j<=i;j++) { if (cha2[j]==0) { printf ("%s ",cha2[j]); } else if (cha2[j]==0) { printf ("Please do not insert character."); } else { printf ("Please do not insert special symbol."); } } } int main () { int a; a=getint(); printf("you entered %d\n", a); return 0; }



LinkBack URL
About LinkBacks



