#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ FILE * fp1 = fopen("file.csv", "r"); FILE * fp2 = fopen("new.csv", "w"); char string[200], toFind[200], updatedWord1[200]; char * line = NULL; char * result = NULL; char * word1 = NULL; char * word2 = NULL; printf("Enter word present in file: "); scanf("%s", toFind); while(fgets(string, 200, fp1)){ // line = strtok(string, "\n"); result = strstr(string, toFind); word1 = strtok(string, ","); word2 = strtok(NULL, ","); if(result) { printf("Enter another word update: "); getchar(); fgets(updatedWord1, 200, stdin); fprintf(fp2, "%s,%s", updatedWord1, word2); } } return 0; }
fgets
fprintf(fp2, "%s,%s", updatedWord1, word2);
word2
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)