#include "stdio.h"
int main(){
float longi;
float lati;
char info[80];
int started = 0;
puts("Data=[");
while((scanf("%f\n%f\n%s",&lati,&longi,info))==3){ //here is my doubt.
printf("\n{latitude:%f, longitude:%f, info:%s},",lati, longi, info);
}
puts("\n]");
}
The above code works as desired, but I figured it out by trial and error. This takes three inputs with the 'enter' key as separator. Initially I supplied:
'\n'
instead of \n
in the format specifier, but that was of no use; it was taking only one input every time.
What's the difference between these two and how does scanf()
handle them?