I have a file that contains a set of characters that I would like to have stored in an array, and was wondering if C's strcat()
function could do the job.
So, would the following be a valid way of getting characters from a file?
FIlE *file = fopen(argv[1], "r");
char ch, *msg[];
while(1)
{
if(feof(file))
{
break;
}
ch = fgetc(file);
strcat(msg,ch);
}
printf("%s", msg);
If I had a file example.txt
containing 12345
, would msg
be 12345
?