null - File is not being opened when inputted. C -
my issue when seek input spath first parameter fopen(); keeps looping wether file exists or not. yet, when hard code parameter test file works properly.i not sure issue is, maybe syntax.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char spath[255], dpath[255]; int c; file *sfp, *dfp; { printf("please come in source file:\n"); fgets(spath, sizeof(spath), stdin); if(strlen(spath) > 253) { while((c = getchar()) != '\n' && c != eof); } }while((sfp=fopen(spath,"r")) == null); }
upon farther reading, fgets() has new line character in array messes things up. prepare use:
for(i = 0 ; < lenght ; i++) { if(array[i] == '\n') array[i] = '\0' ; }
this takes away new line character , insert terminator character. click link farther information: open file user input (string) - c
file null fopen do-while
No comments:
Post a Comment