first use code tags here is your code indented. First one line comments are frownend upon(I hate them) here
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXACCTS 16
#define BUF 64
#define NAME_SZ 10
int main(){
FILE *fp;
FILE *out;
char tname[MAXACCTS][NAME_SZ];
int tid[MAXACCTS], i=0, size =0, k=0;
float tamount[MAXACCTS];
char buffer[BUF];
//open pointers to files transact.txt and accounts.txt
if(( fp = fopen("transact.txt", "r")) == NULL){
perror("UNABLE TO OPEN transact.txt\n");
return -1;
}
if((out = fopen("accounts.txt", "w")) == NULL){
printf("UNABLE TO OPEN accounts.txt\n");
system("pause");
return -2;
}
for(size =0; size < MAXACCTS; ++size){
//read transact.txt and store in buffer
while(fgets(buffer, BUF, fp) != NULL){
str /*where does this come from*/
// read string from file and store information in separate arrays
if(sscanf(buffer,"%d %s %f", &tid[i], tname[i], &tamount[i]) ==3){
//verify id is valid
if(tid[i] > 999 && tid[i] < 10000 ){
//check name for less than ten characters
if(strlen(tname[i]) <NAME_SZ){
//write valid accounts to Accounts.txt
fprintf(out, "%5d\t%10s\t%10.2f\n", tid[i], tname[i], tamount[i]);
}
else
printf("\nERROR: \t Account Name: \"%s\" is over %d characters\n\n", tname[i], NAME_SZ -1);
}
else
printf("\nERROR: \t invalid ID %d\t%s\t\t%.2lf\n", tid[i], tname[i], tamount[i]);
}
else
printf("Invalid transaction");
}
}
printf("the value of size is %d\n", size);
fclose(fp);
fclose(out);
return 0;
}
Did you expect anyone to follow all those nested if statments in a while loop in a for loop.