Thread: Adding structure data in txt file not working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    47

    Adding structure data in txt file not working

    Hello friends,

    i am trying to add structure data to txt file but it gives errors

    Code:
    #include <stdio.h>#include <stdlib.h>
    #include<windows.h>
    /* Use of typedef in Structure */
    
    
    
    
    typedef struct home_address2{
    
    
    char local_street2[100];
    char town2[60];
    char city2[60];
    char country2[60];
    }myaddress2;
    
    
    
    
    
    
    int main(){
    
    
    FILE *ptr;
    ptr=fopen("address.txt","a");
    
    
    
    
        printf("\t\t\t\xB2\xB2\xB2\ ADD RECORD  \xB2\xB2\xB2\xB2");
        printf("\n\n\nEnter Street Address \t\t\Town\t\t\City\t\tCountry :");
        scanf("%s %s %s  %s",&myaddress2.local_street2,&myaddress2.town2,&myaddress2.city2,&myaddress2.country2);
        while(fscanf(ptr,"%s %s %s  %s\n",&myaddress2.local_street2,&myaddress2.town2,&myaddress2.city2,&myaddress2.country2)!=EOF)
        {
    
    
         printf("data added");
        }
         fclose(ptr);
    
    return 0;
    
    
    }
    Last edited by sash_007; 06-29-2019 at 08:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading data from a file and adding them to a list
    By Alex Predova in forum C Programming
    Replies: 1
    Last Post: 06-01-2014, 11:27 PM
  2. Replies: 4
    Last Post: 08-25-2013, 05:09 AM
  3. Adding data to existing data in an input file?
    By matthayzon89 in forum C Programming
    Replies: 4
    Last Post: 11-20-2010, 11:23 PM
  4. adding data to the middle of a file from another file
    By xixpsychoxix in forum C Programming
    Replies: 9
    Last Post: 09-07-2006, 11:00 AM
  5. writing data(adding new records) to the input file
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 07:51 PM

Tags for this Thread