The main difficulty here is in reading the input. Here is a template that does that for you by reading the char after each integer read: char date[10] ; // date fits in 10 chars char separator ; // either a space ' ' or a newline '\n' while( scanf("%s%c", date,&separator) > 0 ) { // we have a new date while(separator!='\n') { int temperature ; scanf("%d%c",&temperature,&separator); // do something with the variable temperature } }