Thread: Get data from a .txt file field by field...

  1. #1
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194

    Get data from a .txt file field by field...

    hi,

    I've created a program that saves and uploads data from a .txt file and into a vector.

    But know im having a small problem, i need to save the data in the .txt file in this format:
    name, adress, phone, etc, etc2

    The program is saving the data in that order, the problem now is that i can't load the data because of that format :-(

    Can anyone tel me how i can load the data, but keeping that format in the .txt file?
    "Artificial Intelligence usually beats natural stupidity."

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    136
    I dont think so that formatting is possible in txt file.

    Once i had used latex to generate formatted output in a pdf file.
    S_ccess is waiting for u. Go Ahead, put u there.

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I don't follow. You just want to save the data into a comma delineated txt file? Why don't you show us some code, and point out where your having trouble
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    111
    if i understand what you wish :
    store the info in that format.
    for example in the txt file you will see :
    name adress phone etc

    the loading will be also the same :
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    
    struct info
    {
    	char name[80];
    	char adrs[10];
    };
    
    int main(void)
    {
        FILE *fp;
        struct info c;
        char str[80];
        float f;
        fp = fopen("/tmp/1.txt","r");
        if (!fp)
        {
            perror(NULL);
            exit(errno);
         }
    	
        while(fscanf(fp, "&#37;s%s", c.name, c.adrs) != EOF) 
        {		
           printf("%s %s",c.name,c.adrs);
        }
    	
        fclose(fp);
    	
        return 0;
    }
    Last edited by jabka; 10-19-2007 at 06:11 PM.
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    fp = fopen("//tmp//1.txt","r");
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351
    Last edited by robwhit; 10-19-2007 at 06:04 PM.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    111
    noted thank you .
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Please Help Reading Data From A File
    By NickHolmes in forum C Programming
    Replies: 5
    Last Post: 05-29-2005, 11:24 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM