I'm C Programming learner.
Please do clear my queries in detail.
< My PC config : Linux with GNU GCC compiler >
1) How to take a file as input which contains integers and display on screen.
I used the following code but its not working :
Code:
# include <stdio.h>
int main ( int argc, int *argv[1] )
{
FILE *fp_file;
int num;
fp_file = fopen ( argv[1], "r" );
fscanf (fp_file,"%d",&num);
fprintf (stdout,"%d",num);
fclose (fp_file);
return ;
}
This is what I used and I'm getting errors. Instead If I replace 'int' by 'char' @ argv[] , @ num and replace %d by %c, its working..
but here the issue is that I'm getting only the first letter of the characters in the file on the screen. Even though I didn't give any white spaces.
I then replaced fscanf() and fprintf() functions with fputc and fgetc but the output is same.
how do I make sure that a) I get the whole characters without using arrays concept. b) how do I get numbers on my screen.
c) can't I use int type in declaring arguments in main function.
2) I want to take input a file which contain some number and my program should read and take that number into a declared variable. how to do it.
* also please give me tips how troubleshoot myself..