Code:
printf("Enter your colleague ID # --> ");
scanf("%d", &user_input);
fp = fopen(DATA_FILE, "r");
/* Generate a string out of the value inputted by user */
sprintf(id_string, "%07d", user_input);
strncpy(number_string, &id_string[4], 3);
number_values = atoi(number_string);
1. You're opening the file with mode "r", but then you try and write to it?
Well that isn't going to change your file is it.
2. What is the point of all that sprintf / strncpy / atoi code?
You convert the number typed in into a string, chop a bit off and convert back to an integer?
If you really wanted to do modulo 1000 on it, it would be far simpler to just write
Besides, you don't \0 terminate the temporary string which atoi() uses (who knows what result you get).
number_values = atoi(&id_string[4]);
would at least save you from a strncpy.
number_values = user_input % 1000;
Replaces all that code if all you wanted was to trim the user input.
Or maybe
number_values = user_input;
if ( user_input >= 1000 ) number_values = 1000;
> printf("This is the number of values: %d\n", number_values);
Put this before the for loop - so you don't clutter the output.