Thread: I dont know how to use printf

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    277

    I dont know how to use printf

    I'm trying to make a dumb program to acess files and stuff, the point is I'm a little bit confused about how to use fprintf, the line:

    printf("%-6%d-16s%-11s%10.2f\n\n", client.accountNumb, client.lastName, client.firstName, client.money);

    gives me several warnings I know it is 99% sure that the error is in this %-6%d-16s%-11s%10.2f\n\n stuff but I cant think a way to make it clear, so if you have any suggestions I would appreciate a lot
    Code:
    #ifdef HAVE_CONFIG_H
    #include <config.h>
    #endif
    
    #include <stdio.h>
    #include <stdlib.h>
    
    struct clientData {
    	int accountNumb;
    	char lastName[15];
    	char firstName[10];
    	float money;
    };
    
    
    int  makeChoice(void);
    void textFile(FILE *);
    void updateRegister(FILE *);
    void insertRegister(FILE *);
    void excludeRegister(FILE *);
    
    
    int main(){
    	FILE *cfPtr;
    	int choice;
    	
    	if ((cfPtr = fopen("credit.dat","r+")) == NULL)
    		printf("File Cannot be Openned\n");
    	else {
    		while ((choice = makeChoice()) != 5) {
    			
    			switch (choice) {
    			 case 1:
    				textFile(cfPtr);
    				break;
    			 case 2:
    				updateRegister(cfPtr);
    				break;
    			 case 3:
    				newRegister(cfPtr);
    				break;
    			 case 4:
    				excludeRegister(cfPtr);
    				break;
    			
    			}
    			
    		}
    		
    		}
    	fclose(cfPtr);
    	return 0;
    }
    
    
    
    void textFile(FILE *readPtr){
    	
    	FILE *storePtr;
    	struct clientData client;
    	
    	if ((storePtr = fopen("accounts.txt", "w")) == NULL)
    		printf("File cannot be openned\n");
    	
    		else { 
    		      rewind(readPtr);
    		      fprintf(storePtr,"%-6s%-16S%-11s%10s\n","Account" , "Last Name", "Name", "Credit");
    			while (!feof(readPtr)){
    				fread(&client, sizeof(struct clientData),1, readPtr);
    				
    				if (client.accountNumb != 0)
    					fprint(storePtr, "%-6d%-16s%-11s%10.2f\n", client.accountNumb, client.lastName, client.firstName, client.money);
    			}
    		}
    		fclose(storePtr);
    }
    
    
    void updateRegister(FILE *fPtr){
    	
    	int account;
    	float transaction;
    	struct clientData client;
    	
    	printf("Give the number of the account you want to update (1-100): ");
    	scanf("%d", &account);
    	
    	fseek(fPtr, (account-1) * sizeof( struct clientData ), SEEK_SET);
    	
    	fread(&client, sizeof( struct clientData ), 1, fPtr);
    	
    	if (client.accountNumb == 0)
    		printf("Account #%d has no info\n", account);
    		
    		else {
    			fprintf("%-6%d-16s%-11s%10.2f\n", client.accountNumb, client.lastName, client.firstName, client.money);
    		printf("Input Debit(+) or Payment(-):");
    		scanf("%f",&transaction);
    		client.money += transaction;
    		printf("%-6%d-16s%-11s%10.2f\n\n", client.accountNumb, client.lastName, 		client.firstName, client.money);
    		fseek(fPtr, (account-1)* sizeof(struct clientData), SEEK_SET);
    		
    		fwrite(&client, sizeof(struct clientData), 1, fPtr);
    		}
    }
    
    void excludeRegister (FILE *fPtr ){
    	struct clientData client, nullClient = {0,"","",0};
    	int accountNumb;
    	
    	printf("Give the Account Number you want to Exclude (1-100): ");
    	scanf("%d", &accountNumb);
    	
    	fseek(fPtr, (accountNumb-1) * sizeof( struct clientData ), SEEK_SET);
    	
    	fread(&client, sizeof(struct clientData) , 1, fPtr);
    	
    	if (client.accountNumb == 0)
    		printf("Account %d doesnt exist\n", accountNumb);
    	
    	else {
    		
    	fseek(fPtr,(accountNumb-1) * sizeof( struct clientData), SEEK_SET);
    	
    	fwrite(&nullClient, sizeof(struct clientData),1, fPtr);
    	}
    }

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Ive found my mistake thx by attention you can close/remove the topic

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM