Thread: Reading in data from Text file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
       char chart1 [11][] = // Array for the Table and Plot points
       {"London", "Bath", "Cardiff", "Carlisle", "Durham", "Exeter", "Leeds", "Norwich", "Truro", "York"},
       {"London", "-", "23", "12", "89", "456", "123", "46", "732", "345", "123"},
       {"Bath", "23", "-", "46", "234", "123", "46", "89", "234", "567", "90"},
       {"Cardiff", "12", "46", "-", "767", "456", "46", "234", "123", "732", "35"},
       {"Carlisle", "89", "234", "767", "-", "732", "32", "48", "67", "98", "100"},
       {"Durham", "456", "123", "456", "732", "-", "234", "46", "89", "89", "732"},
       {"Exeter", "123", "46", "46", "32", "234", "-", "123", "46", "123" "234"},
       {"Leeds", "46", "89", "234", "48", "46", "123", "-", "46", "89", "19"},
       {"Norwich", "732", "234", "123", "67", "89", "46", "46", "-", "123", "732"},
       {"Truro", "345", "567", "732", "98", "89", "123", "89", "123", "-", "78"},
       {"York", "123", "90", "35", "100", "732", "234", "19", "732", "78", "-"};
    Code:
    for (int i = 0; i < (rows); i++)
    {
    	puts(chart1[i]);
    }
    Beware that variables must be defined at the beginning of the function in C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Quote Originally Posted by Elysia View Post
    Code:
       char chart1 [11][] = // Array for the Table and Plot points
       {"London", "Bath", "Cardiff", "Carlisle", "Durham", "Exeter", "Leeds", "Norwich", "Truro", "York"},
       {"London", "-", "23", "12", "89", "456", "123", "46", "732", "345", "123"},
       {"Bath", "23", "-", "46", "234", "123", "46", "89", "234", "567", "90"},
       {"Cardiff", "12", "46", "-", "767", "456", "46", "234", "123", "732", "35"},
       {"Carlisle", "89", "234", "767", "-", "732", "32", "48", "67", "98", "100"},
       {"Durham", "456", "123", "456", "732", "-", "234", "46", "89", "89", "732"},
       {"Exeter", "123", "46", "46", "32", "234", "-", "123", "46", "123" "234"},
       {"Leeds", "46", "89", "234", "48", "46", "123", "-", "46", "89", "19"},
       {"Norwich", "732", "234", "123", "67", "89", "46", "46", "-", "123", "732"},
       {"Truro", "345", "567", "732", "98", "89", "123", "89", "123", "-", "78"},
       {"York", "123", "90", "35", "100", "732", "234", "19", "732", "78", "-"};
    Code:
    for (int i = 0; i < (rows); i++)
    {
    	puts(chart1[i]);
    }
    Beware that variables must be defined at the beginning of the function in C.
    i have just been messing around with the code you gave me and i keep getting this :
    http://i57.photobucket.com/albums/g2...e2k/errors.jpg

    im using DEV-C++ now as its way better then pelles C

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    right after some more messing around with the code i have managed to get the program to run however i get loooadddsssss of errors this is how my string is set out atm
    Code:
        char chart1 [11][11] ={ // Array for the Table and Plot points
       'London', 'Bath', 'Cardiff', 'Carlisle', 'Durham', 'Exeter', 'Leeds', 'Norwich', 'Truro', 'York',
       'London', '-', '23', '12', '89', '456', '123', '46', '732', '345', '123',
       'Bath', '23', '-', '46', '234', '123', '46', '89', '234', '567', '90',
       'Cardiff', '12', '46', '-', '767', '456', '46', '234', '123', '732', '35',
       'Carlisle', '89', '234', '767', '-', '732', '32', '48', '67', '98', '100',
       'Durham', '456', '123', '456', '732', '-', '234', '46', '89', '89', '732',
       'Exeter', '123', '46', '46', '32', '234', '-', '123', '46', '123','234',
       'Leeds', '46', '89', '234', '48', '46', '123', '-', '46', '89', '19',
       'Norwich', '732', '234', '123', '67', '89', '46', '46', '-', '123', '732',
       'Truro', '345', '567', '732', '98', '89', '123', '89', '123', '-', '78',
       'York', '123', '90', '35', '100', '732', '234', '19', '732', '78', '-'};
    below is a screenshot of alll the rubish i get up however i dont understand and know how to fix it

    [img=http://img265.imageshack.us/img265/6919/lolffsdfdsfsfv6.th.jpg]

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by fortune2k View Post
    right after some more messing around with the code i have managed to get the program to run however i get loooadddsssss of errors this is how my string is set out atm
    Code:
        char chart1 [11][11] ={ // Array for the Table and Plot points
       'London', 'Bath', 'Cardiff', 'Carlisle', 'Durham', 'Exeter', 'Leeds', 'Norwich', 'Truro', 'York',
       'London', '-', '23', '12', '89', '456', '123', '46', '732', '345', '123',
       'Bath', '23', '-', '46', '234', '123', '46', '89', '234', '567', '90',
       'Cardiff', '12', '46', '-', '767', '456', '46', '234', '123', '732', '35',
       'Carlisle', '89', '234', '767', '-', '732', '32', '48', '67', '98', '100',
       'Durham', '456', '123', '456', '732', '-', '234', '46', '89', '89', '732',
       'Exeter', '123', '46', '46', '32', '234', '-', '123', '46', '123','234',
       'Leeds', '46', '89', '234', '48', '46', '123', '-', '46', '89', '19',
       'Norwich', '732', '234', '123', '67', '89', '46', '46', '-', '123', '732',
       'Truro', '345', '567', '732', '98', '89', '123', '89', '123', '-', '78',
       'York', '123', '90', '35', '100', '732', '234', '19', '732', '78', '-'};
    Note that 'London' is not valid C of any kind -- only single characters can appear inside single quotes. If you want a string, try "London". Note that this means your array needs to be
    Code:
    char chart1[11][11][]

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Quote Originally Posted by tabstop View Post
    Note that 'London' is not valid C of any kind -- only single characters can appear inside single quotes. If you want a string, try "London". Note that this means your array needs to be
    Code:
    char chart1[11][11][]
    right i have every thing into speeh marks ie. "London", however it wont run now it has a problem with
    char chart1[10][10][] ={ // Array for the Table and Plot points

    it says:
    F:\CCCC\asst_new.cpp In function `int main()':
    7 F:\CCCC\asst_new.cpp declaration of `chart1' as multidimensional array must have bounds for all dimensions except the first
    67 F:\CCCC\asst_new.cpp `chart1' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears in.)

    for char chart1[10][10][] does [10][10][] mean 10 by 10 grid and what does the other one do?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by fortune2k View Post
    right i have every thing into speeh marks ie. "London", however it wont run now it has a problem with
    char chart1[10][10][] ={ // Array for the Table and Plot points

    it says:
    F:\CCCC\asst_new.cpp In function `int main()':
    7 F:\CCCC\asst_new.cpp declaration of `chart1' as multidimensional array must have bounds for all dimensions except the first
    67 F:\CCCC\asst_new.cpp `chart1' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears in.)

    for char chart1[10][10][] does [10][10][] mean 10 by 10 grid and what does the other one do?
    Sorry -- try chart1[10][10][10]. The first is 10 rows, the second is 10 columns, the third is 10 characters in each cell. (That appears to be enough for now -- but if the data could change you may need to change how many characters in each cell.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading data from a text file
    By Dark_Phoenix in forum C++ Programming
    Replies: 8
    Last Post: 06-30-2008, 02:30 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 07:13 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM