i have no problems in writing what i inputted to the FILE...
but i get problems displaying in onscreen to think that the codes are almost similar
except printf(); and fprintf();
can i ask what is wrong? u can run this code by urselves to greater understand what i mean...
P.S... the 2nd for loop isnt displaying what i want it to display [i.e the same display in the FILE, which is correct]
thanks in advance!...
Code:
#include <stdio.h>
typedef struct robot{
char name[50];
int energy;
} ROBOTS;
int main(void)
{
FILE *file = fopen("Data/robots.txt", "w");
int i;
ROBOTS array_robots[3];
clrscr();
if(file==NULL)
{
printf("\n\nError: can't create file.\n\n");
printf("Directory may not exist.\n");
getche();
return 1;
}
else
{
for(i = 0; i < 3; i++)
{
printf("\nEnter a robot's name:\t\t");
scanf("%s", &array_robots[i].name);
printf("\nEnter its energy:\t\t");
scanf("%d", &array_robots[i].energy);
printf("\n\n-------Saving robot...--------\n\n");
}
for(i = 0; i < 3; i++);
{
printf("\nRobot name: \t%s", array_robots[i].name);
printf("\nRobot energy: \t%d", array_robots[i].energy);
printf("\n\n--------------------------");
}
for(i = 0; i < 3; i++)
{
fprintf(file, "\n\nRobot name: \t%s", array_robots[i].name);
fprintf(file, "\nRobot energy: \t%d", array_robots[i].energy);
fprintf(file, "\n\n--------------------------");
}
fclose(file);
getche();
return 0;
}
}