having a problem here

This is a discussion on having a problem here within the C Programming forums, part of the General Programming Boards category; I'm reworking my URL decoder, the first step is to seperate out the input, I made this function up to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    34

    having a problem here

    I'm reworking my URL decoder, the first step is to seperate out the input, I made this function up to read input, but the phone number is coming out wierd, I think its printing the address. Can anyone help me out here?

    Code:
    #define _CRT_SECURE_NO_DEPRECATE
    
    // Compiler Includes
    #include <stdio.h> 
    #include <string.h>
    #include <stdlib.h>
    
    //Constants
    #define MAX_STRING_LENGTH 100 // Maximum file name length
    #define MAX_ARRAY_SIZE 100		// maximum array size
    
    //User defined definitions
    typedef struct { // auto_type structure definition
    	char name[MAX_ARRAY_SIZE];
    	char address[MAX_ARRAY_SIZE];
    	char phoneNumber[MAX_ARRAY_SIZE];
    } PERSON_TYPE;
    
    
    PERSON_TYPE ScanPersonByValue(void);	// function to scan person info
    void PrintPersonInfo (PERSON_TYPE personToPrint);
    
    
    int main (void) {
    
    	//local variable
    
    	PERSON_TYPE personOne = {"\0", "\0", "\0"};
    
    	PrintPersonInfo(personOne);
    
    	personOne = ScanPersonByValue();
    
    	PrintPersonInfo(personOne);
    
    	return 0;
    }
    
    
    PERSON_TYPE ScanPersonByValue (void) {
        PERSON_TYPE inputPerson = {"\0", "\0", "\0" };
        //	char buff[MAX_ARRAY_SIZE] = {"\0"};
    	
    		printf("\nenter your name:");
    		fgets(inputPerson.name sizeof inputPerson.name, stdin);
    		printf("\nenter your address:");
    		fgets(inputPerson.address sizeof inputPerson.address, stdin);
    		printf("\nenter your phone number:");
    		fgets(inputPerson.phoneNumber sizeof inputPerson.phoneNumber, stdin);
    
        return inputPerson;
    }
    
    
    
    void PrintPersonInfo (PERSON_TYPE personToPrint) { 
      
    	printf("\n==================================================================\n");
      printf("NAME: %s            \nADDRESS: %s       \nPHONE: %d\n",personToPrint.name, 
             personToPrint.address, personToPrint.phoneNumber); // prints structures from PERSON_TYPE
    } // end function PrintPersonInfo

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are missing a comma on the "fgets" lines.

    Use "MAX_PATH" for the size of filenames - 100 may be a bit short on some systems. (I do realize you're not using MAX_STRING_SIZE yet, but the comment says that it's the max size of filename).

    --
    Mats

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    34
    Thanks a bunch, figures it was something small like that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21