(I rarely use c functions, so I might have gotten something wrong)
Your names are kind of weird. One could expect searchWord to be the word you are searching for and getLine the line you read with gets, but in fact, it is the other way around.
now when i search a last line of the text file.. for ex "A02-0003" it returns 2 "Pedro Dela Cruz,A02-0003,3" like this
output
Pedro Dela Cruz,A02-0003,3
Pedro Dela Cruz,A02-0003,3
why this happen mate and also when i put else in the if statement where if not found the specific string it output " cannot find Emp ID" and it returns " cannot find Emp ID" but 4 times
i put else after the } of the if statement like this..
Is the break there? If it is, I have no clue why you would get it twice.
If it isn't, it's because fgets fails, reads nothing and you search the same string twice. This is the same reason why you get 4 errors for 3 lines. Try changing the loop to
1 2 3
while(fgets(/*same arguments*/)){
//same searching and printing
}
You have two breaks there, so no matter whether the first line contains what you want or not, the others will not be processed. If you remove the break on line 22 though you'll get several lines of "cannot find string" and only then the line you wanted. Obviously, if you put something in a loop, you should expect it to be repeated. You could solve this with a bool variable, or by puting the loop in a function (that returns a bool) which would be more elegant.. Are you familiar with functions?