I need help i cant figure out how to delete this newline without deleting it from the file if you know what i mean heres my code the problem is in the while loop.Because if i delete the newline right after fgets in the while loop all the text in the file will be horizontal no newlines.so yeah please help.
Code:
int createfile() {
FILE *f;
char filename[256];
char filetext[2048];
printf("File Name:");
scanf("%s",filename);
printf("[%s]",filename);
if((f=fopen(filename,"w")) == NULL) {
printf("Cannot open file %s.\n",filename);
return 0;
}
printf("File %s opened for writing.",filename);
printf("\n------------------------------------\n");
while(1) {
fgets(filetext,2048,stdin);
printf("[%s]",filetext);
if(strstr(filetext,"~")) {
filetext[strlen(filetext) -2] = '\0';
printf("[%s]",filetext);
fprintf(f,"%s",filetext);
break;
}
fprintf(f,"%s",filetext);
}
printf("File %s was created.\n",filename);
fclose(f);
}