#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Load_data to memory


    Hi Guys,

    I am new to C programing. I have the following assignment and what tried. It is not working any tip is appreciated.

    Load_data: This function is automatically called when the program is started. It reads owner and property information from files. If the files do not exist, notify the user, create the files and display the main menu. Once a file is open, data is read into an array of structs by dynamically creating sufficient memory for each entry read from the file.

    Define a struct to represent the information for an owner, containing the following fields:

    • Number (int)
    • Name (char[])
    • E-mail address (char[])
    • Phone number (char[])

    Define a struct to represent the information for a property, containing the following fields:

    • Owner (char[])
    • Zip code (int)
    • Property number (int)
    • Bedrooms (int)
    • Rental amount (float)

    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>

    struct {
    int number;
    char name[36];
    char email[20];
    char phone[10];
    } Owner;

    struct {
    char owner_name[36];
    char zipcode[12];
    char phone_number[20];
    int bedrooms;
    float rental_amount;
    } Property;

    int main(void)
    {
    /* declare a file pointer */
    FILE *infile1,*infile2;
    char *buffer;
    long numbytes;



    /* open an existing file for reading */
    infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
    infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");

    /* quit if the file does not exist */
    if(infile1&&infile2 == NULL)
    return 1;

    /* Get the number of bytes */
    fseek(infile1&&infile2, 0L, SEEK_END);
    numbytes = ftell(infile1&&infile2);

    /* reset the file position indicator to
    the beginning of the file */
    fseek(infile1&&infile2, 0L, SEEK_SET);

    /* grab sufficient memory for the
    buffer to hold the text */
    buffer = (char*)calloc(numbytes, sizeof(char));

    /* memory error */
    if(buffer == NULL)
    return 1;

    /* copy all the text into the buffer */
    fread(buffer, sizeof(char), numbytes, infile1&&infile2);
    fclose(infile1&&infile2);

    /* confirm we have read the file by
    outputing it to the console */
    printf("The file called test.dat contains this text\n\n%s", buffer);

    /* free the memory we used for the buffer */
    free(buffer);

    return 0;
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    Check this line out

    Code:
    #define REC_SIZE = 10
    Also, please use code tags when you post code.

    Note I tried compiling your program and recieved a few errors and warnings.

    The errors
    Code:
    test.c: In function ‘load_data’:
    test.c:57:14: warning: assignment makes integer from pointer without a cast [enabled by default]
    test.c:58:12: error: incompatible types when assigning to type ‘char[36]’ from type ‘char *’
    test.c:59:13: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’
    test.c:60:13: error: incompatible types when assigning to type ‘char[10]’ from type ‘char *’
    test.c:62:8: error: ‘index’ undeclared (first use in this function)
    test.c:62:8: note: each undeclared identifier is reported only once for each function it appears in
    test.c:42:7: warning: unused variable ‘token’ [-Wunused-variable]
    test.c:40:8: warning: unused variable ‘j’ [-Wunused-variable]
    test.c:40:5: warning: unused variable ‘i’ [-Wunused-variable]
    test.c:39:6: warning: unused variable ‘buffer’ [-Wunused-variable]
    test.c: In function ‘main’:
    test.c:79:1: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    test.c:80:16: error: ‘index’ undeclared (first use in this function)
    test.c:83:1: error: expected declaration or statement at end of input
    test.c:74:21: warning: unused variable ‘propertyFilePtr’ [-Wunused-variable]
    test.c:74:7: warning: variable ‘ownerFilePtr’ set but not used [-Wunused-but-set-variable]
    test.c:73:7: warning: unused variable ‘property_filename’ [-Wunused-variable]
    test.c:83:1: warning: control reaches end of non-void function [-Wreturn-type]
    [gerard@localhost test]$ clear
    [gerard@localhost test]$ man strtok
    [gerard@localhost test]$ gcc test.c -Wall -ansi -pedantic -o test
    test.c: In function ‘load_data’:
    test.c:57:14: warning: assignment makes integer from pointer without a cast [enabled by default]
    test.c:58:12: error: incompatible types when assigning to type ‘char[36]’ from type ‘char *’
    test.c:59:13: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’
    test.c:60:13: error: incompatible types when assigning to type ‘char[10]’ from type ‘char *’
    test.c:62:8: error: ‘index’ undeclared (first use in this function)
    test.c:62:8: note: each undeclared identifier is reported only once for each function it appears in
    test.c:42:7: warning: unused variable ‘token’ [-Wunused-variable]
    test.c:40:8: warning: unused variable ‘j’ [-Wunused-variable]
    test.c:40:5: warning: unused variable ‘i’ [-Wunused-variable]
    test.c:39:6: warning: unused variable ‘buffer’ [-Wunused-variable]
    test.c: In function ‘main’:
    test.c:79:1: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    test.c:80:16: error: ‘index’ undeclared (first use in this function)
    test.c:83:1: error: expected declaration or statement at end of input
    test.c:74:21: warning: unused variable ‘propertyFilePtr’ [-Wunused-variable]
    test.c:74:7: warning: variable ‘ownerFilePtr’ set but not used [-Wunused-but-set-variable]
    test.c:73:7: warning: unused variable ‘property_filename’ [-Wunused-variable]
    test.c:83:1: warning: control reaches end of non-void function [-Wreturn-type]
    How can you write code and have so many errors and warnings? When I write code I compile it with every change or addition.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,143
    Rep Power
    2222
    Originally Posted by slemma
    It is not working any tip is appreciated.
    Tip #1: Instead of just simply saying "It is not working", tell us what that is supposed to mean. Won't compile? Won't run? Ignores input? Gives wrong output? Get output with minor glitches line leaving out a single space? All of that and infinitely more is encompassed by "It is not working", so you really do need to be much more specific.

    Tip #2: Use code tags!

    Heeding both tips will take you very far here.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    I am sorry i loaded a wrong code. I have edit it.

    Code:
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    
     struct {
        int number;
        char name[36];
        char email[20];
        char phone[10];
    } Owner;
    
     struct {
        char owner_name[36];
        char zipcode[12];
        char phone_number[20];
        int bedrooms;
        float rental_amount;
    } Property;
    
    int main(void)
    {
    /* declare a file pointer */
    FILE    *infile1,*infile2;
    char    *buffer;
    long    numbytes;
    
    
    
    /* open an existing file for reading */
    infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
    infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");
    
    /* quit if the file does not exist */
    if(infile1&&infile2 == NULL)
        return 1;
    
    /* Get the number of bytes */
    fseek(infile1&&infile2, 0L, SEEK_END);
    numbytes = ftell(infile1&&infile2);
    
    /* reset the file position indicator to
    the beginning of the file */
    fseek(infile1&&infile2, 0L, SEEK_SET);
    
    /* grab sufficient memory for the
    buffer to hold the text */
    buffer = (char*)calloc(numbytes, sizeof(char));
    
    /* memory error */
    if(buffer == NULL)
        return 1;
    
    /* copy all the text into the buffer */
    fread(buffer, sizeof(char), numbytes, infile1&&infile2);
    fclose(infile1&&infile2);
    
    /* confirm we have read the file by
    outputing it to the console */
    printf("The file called test.dat contains this text\n\n%s", buffer);
    
    /* free the memory we used for the buffer */
    free(buffer);
    
    return 0;
    }
    Originally Posted by G4143
    Check this line out

    Code:
    #define REC_SIZE = 10
    Also, please use code tags when you post code.

    Note I tried compiling your program and recieved a few errors and warnings.

    The errors
    Code:
    test.c: In function ‘load_data’:
    test.c:57:14: warning: assignment makes integer from pointer without a cast [enabled by default]
    test.c:58:12: error: incompatible types when assigning to type ‘char[36]’ from type ‘char *’
    test.c:59:13: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’
    test.c:60:13: error: incompatible types when assigning to type ‘char[10]’ from type ‘char *’
    test.c:62:8: error: ‘index’ undeclared (first use in this function)
    test.c:62:8: note: each undeclared identifier is reported only once for each function it appears in
    test.c:42:7: warning: unused variable ‘token’ [-Wunused-variable]
    test.c:40:8: warning: unused variable ‘j’ [-Wunused-variable]
    test.c:40:5: warning: unused variable ‘i’ [-Wunused-variable]
    test.c:39:6: warning: unused variable ‘buffer’ [-Wunused-variable]
    test.c: In function ‘main’:
    test.c:79:1: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    test.c:80:16: error: ‘index’ undeclared (first use in this function)
    test.c:83:1: error: expected declaration or statement at end of input
    test.c:74:21: warning: unused variable ‘propertyFilePtr’ [-Wunused-variable]
    test.c:74:7: warning: variable ‘ownerFilePtr’ set but not used [-Wunused-but-set-variable]
    test.c:73:7: warning: unused variable ‘property_filename’ [-Wunused-variable]
    test.c:83:1: warning: control reaches end of non-void function [-Wreturn-type]
    [gerard@localhost test]$ clear
    [gerard@localhost test]$ man strtok
    [gerard@localhost test]$ gcc test.c -Wall -ansi -pedantic -o test
    test.c: In function ‘load_data’:
    test.c:57:14: warning: assignment makes integer from pointer without a cast [enabled by default]
    test.c:58:12: error: incompatible types when assigning to type ‘char[36]’ from type ‘char *’
    test.c:59:13: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’
    test.c:60:13: error: incompatible types when assigning to type ‘char[10]’ from type ‘char *’
    test.c:62:8: error: ‘index’ undeclared (first use in this function)
    test.c:62:8: note: each undeclared identifier is reported only once for each function it appears in
    test.c:42:7: warning: unused variable ‘token’ [-Wunused-variable]
    test.c:40:8: warning: unused variable ‘j’ [-Wunused-variable]
    test.c:40:5: warning: unused variable ‘i’ [-Wunused-variable]
    test.c:39:6: warning: unused variable ‘buffer’ [-Wunused-variable]
    test.c: In function ‘main’:
    test.c:79:1: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    test.c:80:16: error: ‘index’ undeclared (first use in this function)
    test.c:83:1: error: expected declaration or statement at end of input
    test.c:74:21: warning: unused variable ‘propertyFilePtr’ [-Wunused-variable]
    test.c:74:7: warning: variable ‘ownerFilePtr’ set but not used [-Wunused-but-set-variable]
    test.c:73:7: warning: unused variable ‘property_filename’ [-Wunused-variable]
    test.c:83:1: warning: control reaches end of non-void function [-Wreturn-type]
    How can you write code and have so many errors and warnings? When I write code I compile it with every change or addition.
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Nice ideas, but this is not how c works. The expression
    a && b
    produces 0 or 1. It does not mean "do this function to both items".

    Handling both files together is a good idea, to the extent that it's possible. You could make an array of FILE*infiles[2] and loop over that array. Without that array, using infile1 and infile2 of your program, you'll need to write more code treating the files separately. For example:

    Code:
      /* open an existing file for reading */
      infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
      if(NULL == infile1)		/* quit if the file does not exist */
        return 1;
      infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");
      if(NULL == infile2) {		/* quit if the other file does not exist */
        fclose(infile1);		/* this file was opened, close it */
        return 2;
      }
    
      /* Get the number of bytes in the owner file*/
      fseek(infile1, 0L, SEEK_END);
      numbytes_in_owner = ftell(infile1);
      fseek(infile1, 0L, SEEK_SET);
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    Thank you for your help but i am still getting unorganized output. Here is the requirement: Load_function- is automatically called when the program is started. It reads owner and property information from files. If the files do not exist, notify the user, create the files and display the main menu. Once a file is open, data is read into an array of structs by dynamically creating sufficient memory for each entry read from the file.

    Define a struct to represent the information for an owner, containing the following fields:

    • Number (int)
    • Name (char[])
    • E-mail address (char[])
    • Phone number (char[])

    Define a struct to represent the information for a property, containing the following fields:

    • Owner (char[])
    • Zip code (int)
    • Property number (int)
    • Bedrooms (int)
    • Rental amount (float)

    Originally Posted by b49P23TIvg
    Nice ideas, but this is not how c works. The expression
    a && b
    produces 0 or 1. It does not mean "do this function to both items".

    Handling both files together is a good idea, to the extent that it's possible. You could make an array of FILE*infiles[2] and loop over that array. Without that array, using infile1 and infile2 of your program, you'll need to write more code treating the files separately. For example:

    Code:
      /* open an existing file for reading */
      infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
      if(NULL == infile1)		/* quit if the file does not exist */
        return 1;
      infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");
      if(NULL == infile2) {		/* quit if the other file does not exist */
        fclose(infile1);		/* this file was opened, close it */
        return 2;
      }
    
      /* Get the number of bytes in the owner file*/
      fseek(infile1, 0L, SEEK_END);
      numbytes_in_owner = ftell(infile1);
      fseek(infile1, 0L, SEEK_SET);
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    You know that some of your data is not text...

    Code:
    struct {
        int number;/*not text*/
        char name[36];
        char email[20];
        char phone[10];
    } Owner;
    
     struct {
        char owner_name[36];
        char zipcode[12];
        char phone_number[20];
        int bedrooms;/*not text*/
        float rental_amount;/*not text*/
    } Property;
    So this may not(will not) display those noted fields properly.

    Code:
    printf("The file called test.dat contains this text\n\n%s", buffer);
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    You will fail this assignment until you understand that

    infile1&&infile2 == NULL

    means

    infile1 && (infile2 == NULL)

    true only when infile1 opened successfully and infile2 did not open.


    ftell(infile1&&infile2)

    ftell needs a pointer to a FILE type. You have given ftell either a 0 or a 1.
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    Thanks for your help. I got it to work but now i am trying to right it in to an array of structs but output is not what i expected. I do not know what i am doing wrong. Below is the code: Any tip is appreciated.

    Code:
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    
     struct {
        int number;
        char name[36];
        char email[20];
        char phone[10];
    } owner;
    
     struct {
        char owner_name[36];
        int zipcode;
        int number;
        int bedrooms;
        float rental_amount;
    } property;
    
    int main(void)
    {
    /* declare a file pointer */
    FILE    *infile1,*infile2;
    char    *buffer;
    long    numbytes;
    long    numbytes_in_owner;
    long    numbytes_in_property;
    int i;
    char name[100];
    
    
    
    
    /* open an existing file for reading */
    infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
    if(NULL == infile1)
    return 1;
    infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");
    if(NULL == infile2) {		/* quit if the other file does not exist */
        fclose(infile1);		/* this file was opened, close it */
        return 2;
      }
    
    /* quit if the file does not exist */
    //if(infile1&&infile2 == NULL)
        //return 1;
    
    /* Get the number of bytes */
    fseek(infile1, 0L, SEEK_END);
    numbytes_in_owner = ftell(infile1);
    fseek(infile1, 0L, SEEK_SET);
    
    fseek(infile2, 0L, SEEK_END);
    numbytes_in_property = ftell(infile2);
    fseek(infile2, 0L, SEEK_SET);
    
    /* reset the file position indicator to
    the beginning of the file */
    fseek(infile1, 0L, SEEK_SET);
    fseek(infile2, 0L, SEEK_SET);
    
    /* grab sufficient memory for the
    buffer to hold the text */
    buffer = (char*)calloc(numbytes, sizeof(char));
    //buffer = malloc(numbytes * sizeof(char));
    
    /* memory error */
    if(buffer == NULL)
        return 1;
    
    /* copy all the text into the buffer */
    fread(buffer, sizeof(char), numbytes, infile1);
    fread(buffer, sizeof(char), numbytes, infile2);
    fclose(infile1);
    fclose(infile2);
    
    
    
    fscanf(infile1, "%s,%d,%s,%d", &owner.number, owner.name,owner.email,&owner.phone);
        fclose(infile1);
              printf("owner number:%s - name:%d - email:%s - phone:%d",&owner.number, owner.name,owner.email,&owner.phone);
    
    fscanf(infile2, "%s,%d,%d,%d,%2f", &property.owner_name, property.zipcode,property.number,property.bedrooms,&property.rental_amount);
        fclose(infile1);
              printf("Property owner:%s - name:%d - email:%s - phone:%d",&property.owner_name, property.zipcode,property.number,property.bedrooms,&property.rental_amount);
    
    
    
    /* confirm we have read the file by
    outputing it to the console */
    printf("The files are \n\n%s", buffer);
    
    /* free the memory we used for the buffer */
    free(buffer);
    
    int choice, shift;
    
    Label1:
    
        printf  ("\t************************************");
        printf("\n\t*        MENU                      *");
    
    
               //Label1
    
        printf("\n\t*   1. add owner                   *");
        printf("\n\t*   2. add property                *");
        printf("\n\t*   3. View property info          *");
        printf("\n\t*   4. sort owner info             *");
        printf("\n\t*   5. view property info by rent  *");
        printf("\n\t*   6. sort property info          *");
        printf("\n\t*   7. sort owner info by pr number*");
        printf("\n\t*   8. view pr info by bedroom     *");
        printf("\n\t*   9. exit                        *");
        printf("\n\t************************************");
    
    
        printf("\n Please type your choice: ");
        scanf ("%d", &choice);
        //return option;
    
    
       // printf("\n Please enter 5 integers:");
       // scanf ("%d %d %d %d %d", &one, &two, &three, &four, &five);
    
    
        switch(choice)
            {
    //add owner
    case 1:
    Label2:
    
    printf("\n enter the owner info \n");
    printf("\n enter the owner number =");
    scanf("%d",&owner.number);
    printf("\n enter the owner name =");
    scanf("%d",owner.name);
    printf("\n enter the Email=");
    scanf("%s",owner.email);
    printf("\n enter the owners phone=");
    scanf("%s",&owner.phone);
    infile1=fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt","a+");
    fprintf(infile1,"\n%d\t%s\t%s\t%d\t",owner.number, owner.name,owner.email,owner.phone);
    fclose(infile1);
    
    
           printf("Owner record has been added successfully...\n");
           printf("\n\n1 -> Wish to add another record");
           printf("\n2 -> Wish to move to Main Menu");
           printf("\n3 -> Exit from Program\n");
           scanf("%d",&shift);
           if(shift==1)
            goto Label2;
           if(shift==2)
            goto Label1;
           if(shift==3)
            break;
           if(shift!=1&&2&&3){
            printf("Exiting.........");
            break;
    
            }
    
    return 0;
    }
    }
    Originally Posted by b49P23TIvg
    Nice ideas, but this is not how c works. The expression
    a && b
    produces 0 or 1. It does not mean "do this function to both items".

    Handling both files together is a good idea, to the extent that it's possible. You could make an array of FILE*infiles[2] and loop over that array. Without that array, using infile1 and infile2 of your program, you'll need to write more code treating the files separately. For example:

    Code:
      /* open an existing file for reading */
      infile1 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\owner.txt", "r");
      if(NULL == infile1)		/* quit if the file does not exist */
        return 1;
      infile2 = fopen("C:\\Users\\slemma\\Desktop\\FiC++\\MyC++\\property.txt", "r");
      if(NULL == infile2) {		/* quit if the other file does not exist */
        fclose(infile1);		/* this file was opened, close it */
        return 2;
      }
    
      /* Get the number of bytes in the owner file*/
      fseek(infile1, 0L, SEEK_END);
      numbytes_in_owner = ftell(infile1);
      fseek(infile1, 0L, SEEK_SET);
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    186
    Rep Power
    82
    Code:
    fscanf(infile1, "%s,%d,%s,%d", &owner.number, owner.name,owner.email,&owner.phone);
    Is the above code correct? You're reading owner.number as a char and owner.name as a int. Shouldn't it be vice versa?

    Code:
     printf("owner number:%s - name:%d - email:%s - phone:%d",&owner.number, owner.name,owner.email,&owner.phone);
    Same thing with the above code.
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    it's not working. you lie.
    Code:
    /* reset the file position indicator to
    the beginning of the file */
    fseek(infile1, 0L, SEEK_SET);   /*****************you already moved to the beginning of the files*****************/
    fseek(infile2, 0L, SEEK_SET);
    
    /* grab sufficient memory for the
    buffer to hold the text */
    buffer = (char*)calloc(numbytes, sizeof(char)); /***************** using uninitialized numbytes ****************/
    //buffer = malloc(numbytes * sizeof(char));     /***************** I won't tell you again ****************/
    
    /* memory error */
    if(buffer == NULL)                      /***************** if you want a job sometime in the future, write *****************/
        return 1;                           /***************** if (NULL == buffer) ****************/
    
    /* copy all the text into the buffer */
    fread(buffer, sizeof(char), numbytes, infile1);
    fread(buffer, sizeof(char), numbytes, infile2); /***************** reading into same memory overwrites what you just read. **************** almost certainly a mistake ****************/
    [code]Code tags[/code] are essential for python code and Makefiles!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    you see one of the causes of conflict is perception. or you may have other agenda. I am here to learn, there is no reason to lie, if you were nice and ask what part is working, i would tell you. The opening file is working but the reading in to array of structs is what is not working. You do not have to reply anymore, the other guy knows exactly what is missing, he/she understood my issue, perhaps he/she has the other additional knowledge, other than the technical part, which more employers require.

    God Bless you!


    Originally Posted by b49P23TIvg
    it's not working. you lie.
    Code:
    /* reset the file position indicator to
    the beginning of the file */
    fseek(infile1, 0L, SEEK_SET);   /*****************you already moved to the beginning of the files*****************/
    fseek(infile2, 0L, SEEK_SET);
    
    /* grab sufficient memory for the
    buffer to hold the text */
    buffer = (char*)calloc(numbytes, sizeof(char)); /***************** using uninitialized numbytes ****************/
    //buffer = malloc(numbytes * sizeof(char));     /***************** I won't tell you again ****************/
    
    /* memory error */
    if(buffer == NULL)                      /***************** if you want a job sometime in the future, write *****************/
        return 1;                           /***************** if (NULL == buffer) ****************/
    
    /* copy all the text into the buffer */
    fread(buffer, sizeof(char), numbytes, infile1);
    fread(buffer, sizeof(char), numbytes, infile2); /***************** reading into same memory overwrites what you just read. **************** almost certainly a mistake ****************/
  24. #13
  25. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I agree that G4143 gives valuable insight. I didn't bother to check BobS0327 because the comments were so blatant they almost had to be correct.

    On the other hand, you said
    Originally Posted by slemma
    I got it to work
    And there is no way the code you posted solves the problem you posted. Of course, you may have meant by "it to work" that you successfully clipped your toenails without cutting badly yourself.

    If you are truly here to learn, read your own program!
    [code]Code tags[/code] are essential for python code and Makefiles!
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    lol.....you sound like you are running for washington office. Why do you have to cut the sentence to make it look like i said it worked. This is what i exactly said "Thanks for your help. I got it to work but now i am trying to right it in to an array of structs but output is not what i expected. I do not know what i am doing wrong. Below is the code: Any tip is appreciated." if it worked why bother to post it. Look, it is about 9pm mountain time, go get good movie, make some herbal tea and enjoy.

    God Bless you!



    Originally Posted by b49P23TIvg
    I agree that G4143 gives valuable insight. I didn't bother to check BobS0327 because the comments were so blatant they almost had to be correct.

    On the other hand, you said
    And there is no way the code you posted solves the problem you posted. Of course, you may have meant by "it to work" that you successfully clipped your toenails without cutting badly yourself.

    If you are truly here to learn, read your own program!

IMN logo majestic logo threadwatch logo seochat tools logo