Answer the question
In order to leave comments, you need to log in
Why, when reading a file, does it not write values after processing?
There is code that reads incoming values.
#include <stdio.h>
int main(){
char city[80];
char index[80];
int started = 0;
puts("data=[");
while(scanf("%79,%79[^\n]", city, index)==2){
if(started){
printf(",\n");
}
else{
started = 1;
}
printf("{CITY = %s INDEX = %s}", city, index);
}
printf("\n]");
return 0;
}
Moscow,RU
London,EN
Minsk,BY
test < city.txt > outfile.txt
data=[
]
Answer the question
In order to leave comments, you need to log in
Try the following expression in scanf:
scanf("%79[^,],%79[^\n]\n", city, index)
the first [^,] means to read until a comma is encountered, the second comma is to skip the comma character . A similar situation with \n.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question