I want to know why the telephone number saved as other thing. The C++ Code will be post in the comment.
#include <stdio.h> #include <stdlib.h> void authenticity (int age); void main () { system ("title Assignment A5"); system ("color 1F"); int counter; int g=0,f=0; struct callersinfo { char callername[20]; char telno[11]; int age; }; typedef callersinfo callperson; callperson caller[10]; FILE *input; input=fopen("callersinfo.dat", "w"); if (input ==NULL) { printf("\nThe file failed to create\n"); exit(-1); } printf("Fire Brigade Department\n\n"); for (counter = 0;counter <= 9; ++ counter) { printf("Caller number %d\n",counter+1); printf("Enter Caller's Name: "); scanf("%s",&caller[counter].callername); printf("Enter Caller's phone numbers: "); scanf("%d",&caller[counter].telno); printf("Enter caller's age: "); scanf("%d",&caller[counter].age); fprintf(input,"Name: %s\n",caller[counter].callername); fprintf(input,"Tel. No.: %d\n",caller[counter].telno); fprintf(input,"Age: %d\n",caller[counter].age); authenticity (caller[counter].age); if (caller[counter].age >=10) { g++; } else { f++; } } fclose(input); printf("Summary:\nTotal number of callers: %d\nNumber of genuine emergency calls: %d\nNumber of fake calls: %d\n",counter,g,f); return; }; void authenticity (int age) { int type; if (age>=10) { type=1; printf("Type of call: %d\n",type); printf("THE CALL IS A GENUINE EMERGENCY CALL.\n\n"); } else { type=2; printf("Type of call: %d\n",type); printf("THE CALL MAY BE FAKE! BE CAUTIOUS!\n\n"); } }
you mean why the telephone number is saved as a char pointer but not as an int ?
when i type the tel no For example:012345678 it save as a number around 1244XXX it should save 012345678 but not the number above.... Anything wrong with my code?
Oh i found something... trying see it's work or not....
Join our real-time social learning platform and learn together with your friends!