mjs84
Aerospace
- Aug 20, 2003
- 27
I am new to C and I'm having a problem with something I thought would be relatively simple.
I am trying to read a character at a time from a string, using the getchar() function, and I seem to be having alot of trouble.
Below is my code:
*---------------------------------------------------------
FILE *fp0;
char c(10+1);
int j, ch;
fopen(fp0, "outfilename","w"
for ( j=0 ; (j<10) && ((ch=getchar()) != EOF) && (ch != '/n') ; j++)
{
c[j] = (char)ch;
fprintf(fp0, "c = %c/n", c[j]);
}
fclose(fp0);
*---------------------------------------------------------
This compiles okay, but hangs up when it's executed.
Any help would be greatly appreciated.
Regards,
mjs84
I am trying to read a character at a time from a string, using the getchar() function, and I seem to be having alot of trouble.
Below is my code:
*---------------------------------------------------------
FILE *fp0;
char c(10+1);
int j, ch;
fopen(fp0, "outfilename","w"
for ( j=0 ; (j<10) && ((ch=getchar()) != EOF) && (ch != '/n') ; j++)
{
c[j] = (char)ch;
fprintf(fp0, "c = %c/n", c[j]);
}
fclose(fp0);
*---------------------------------------------------------
This compiles okay, but hangs up when it's executed.
Any help would be greatly appreciated.
Regards,
mjs84