> if ( count > 3)
It should be changed to "if ( count > 2)". You are starting from 0 and he wants anything more than 3!
And sanko50, sunnycoder has not given code for reading from a file. Hope you know that part already! Anyway, I will give steps to achieve this:
1. Open file "sample.txt".
2. read line to buffer "string". (sunny has hardcoded data of string. If you remove that and add my algorithm, then you will have complete code).
3. Repeat step# 2 till EOF.
Hope you can convert these to code and make it work!
Main Topics
Browse All Topics





by: sunnycoderPosted on 2004-01-11 at 22:40:47ID: 10093754
Hi sanko50,
char last_char;
int count=0;
char string[] = "0 0 0 0 0 1 2 2 0 0";
char * temp = string;
last_char = * temp;
/* loop over input begin */
while ( * temp == last_char )
{
count++;
temp = temp+2; //+2 for intervening space
}
if ( count > 3)
/* print * last_char count* */
printf ( "*%c%d*",last_char,count);
else
/* print last_char count times */
last_char = *temp;
count = 0;
/* loop over input end*/
I hope you can fill in the blanks
Cheers!
Sunny:o)