Hi ppl,

Im new here and also new to C programming on Linux. Im trying to create a file and enter some data to it; but the output file is strange.

My Code :====================================

struct Student {

char name[20];
char studentID[10];
char dob[8];
char gender[1];
char marital[1];

};

main() {

struct Student A[5];

int i;
int file, op;

file = open("input.dat",O_CREAT|O_WRONLY);

for (i=0;i<1;i++) {

printf("\nEnter details for student %d \n", (i+1));

printf("Enter Name : ");
scanf("%s", A[i].name);
op = write(file, A[i].name, 20);

printf("Enter StudentID : ");
scanf("%s",A[i].studentID);
op = write(file, A[i].studentID, 10);

printf("Enter Date of Birth : ");
scanf("%s", A[i].dob);
op = write(file, A[i].dob, 8);

printf("Enter Gender : ");
scanf("%s",A[i].gender);
op = write(file, A[i].gender, 1);

printf("Enter Marital Status : ");
scanf("%s", A[i].marital);
op = write(file, A[i].marital, 1);

op = write(file, "\n", 2);
}

close(file);

}

===================================
I have entered these data:

Michael - 0510234 - 050286 - m - n

===================================
Output in the file:
michaelNUL+wNULNULNULNULpSO\NUL0510234NULNa050286N ULNULmn
NUL

Watsup with all these NULs ? :S

I tried to read these data from the file to disaplay them, but i got only michael to display.


Please help a beginner! :P

Thank you!