html - Form Data to CSV File -
i have written c code, not appear working correctly. have post form , looking tokenize output (based on & limiting character) , write output text file (with commas separating data).
any suggestions on coding?
int main () { static const char write2file[] = "csvoutput.txt"; file *fp = fopen ( write2file, "w" ); char line[128], str[128]; char *p, *pch; // while stdin not null while ( fgets (line) != null ) { // tokenize string based on & character pch = strtok (line,"&"); // writes token file fputs(pch,fp); // writes comma file fputc(',',fp); // writes token file fputs(pch,fp); // takes new line break fputc('\n',fp); } fclose ( fp ); }
you calling fgets few params
char * fgets ( char * str, int num, file * stream ); you want post?
char *slen; char *post; int len; slen = getenv("content_length"); if (slen && sscanf(slen, "%d", &len) == 1) { post = malloc((size_t)len + 1); /* check malloc */ fgets(post, len + 1, stdin); /* strtok here */ free(post); }
Comments
Post a Comment