I am trying to read a file and then read each character until i reach a new line the do some work on that line. Here is what i have done so far:
char line[] = "";
char *charcter = "";
//If i do this here it works fine, but below it's not working at all
charcter = "asssss";
strcat(line,charcter);
//Read file
inputFile = fopen(fileName,"r");
if (inputFile)
{
while ((charcter = (char)getc(inputFile)) != EOF)
strcat(line,charcter); //This piece code keeps crashing my program on run
fclose(inputFile);
}
I am a C# developer and i am really frustrated that i can't figure out this thing, please help.
Edit:
I have modified the piece line and allocated memory to it like this:
char *line = (char*)malloc( 400 *sizeof(char));
now the strcat in the while loop works but crashes after taking all the values (the input is much smaller than the allocated memory), and if i put the same strcat statment inside an if statment it will take the first letter then crash.
So what is the problem here ?