Hi this is an assignment for my computer science lab. It is weird because if I compile and run with my c compiler from ubuntu gcc4.4, it works perfectly. But if I compile with the university's server (I connect with SSH) it messes up
The main purpose of the program is to change every first character of the name to uppercase
The textfile should contain this
ID FIRSTNAME LASTNAME
10 efron berlian
20 jim smith
30 what ever
the program will change the file to
ID FIRSTNAME LASTNAME
10 Efron Berlian
20 Jim Smith
30 What Ever
#include<stdio.h>
#include<ctype.h>
int main()
{
char buffer[256]; //just a temp variable to store input
int intTemp; //temporary integer to store input
char charTemp1[40]; //temporary strings to store input
char charTemp2[40]; //temporary strings to store input
FILE *filePtr;
fpos_t position; //save the position of the file Pointer
filePtr = fopen("employee.dat", "r+"); //open the file for reading and writing
fgets(buffer, 256, filePtr); //go through the first line doing nothing
fgetpos(filePtr, &position); //save the pointer at beginning of second line
while(fgets(buffer, 256, filePtr) != NULL)
{
//fix the file
sscanf(buffer, "%d %s %s", &intTemp, charTemp1, charTemp2);
printf("before: %s %s\n", charTemp1, charTemp2);
*charTemp1 = toupper(*charTemp1);
*charTemp2 = toupper(*charTemp2);
printf("after: %s %s\n", charTemp1, charTemp2);
//print it back to the file
fsetpos(filePtr, &position); //set position to before the reading happens
fprintf(filePtr, "%d\t%s\t%s\n", intTemp, charTemp1, charTemp2); //print it back into the file
fgetpos(filePtr, &position); //save the pointer at the current position
}
fclose(filePtr);
return 0;
}
can anyone tell me why? btw the server's gcc is 4.3
Thanks
Edit:
The output from my compiler:
efron@Caladbolg:~/Desktop/Lab7$ gcc fixcap.c
efron@Caladbolg:~/Desktop/Lab7$ ./a.out
before: efron berlian
after: Efron Berlian
before: jim smith
after: Jim Smith
before: what ever
after: What Ever
efron@Caladbolg:~/Desktop/Lab7$
The output from the server's compiler:
luna:~/60-141/Lab/Lab7>gcc fixcap.c
luna:~/60-141/Lab/Lab7>./a.out
before: efron berlian
after: Efron Berlian
before: efron berlian
after: Efron Berlian
before: jim smith
after: Jim Smith
before: Jim Smith
after: Jim Smith
luna:~/60-141/Lab/Lab7>gcc --version
gcc (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
luna:~/60-141/Lab/Lab7>