Thread: Problem with char declaration...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    14

    Unhappy Problem with char declaration...

    hi,

    there is my problem, i'm new to C and i'm doing a project and I have something I've never seen before plz help...

    char firstname[7][15], name[7][15];
    ( what is a char with [][], I think is 7*15 arrays...)

    and now i want to make a struct , max lenght of the arrays must be 20...

    so

    struct Names {
    char firstname[20];
    char name[20];
    } TEST[7][15];

    ( is it ok???!!!???)

    and those arrays will be stored in a *.dat, what the best way to access them...

    Thanks in advance for help, everything will be appreciated...

    Mars Volta

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    answer is yes and no,
    try:
    Code:
    struct names { 
    char firstname[20]; 
    char name[20]; 
    } NAMES;
    
    int main()
    {
      NAMES TEST[7][15]; 
    }
    depends try out fgets and fscanf and see which one suits you best

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    14
    ok thx a LOT!

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >what is a char with [][], I think is 7*15 arrays...
    Correct, this is the notation for a two dimensional array, also refered to as a matrix or table. It declares 7 arrays each 15 characters long.

    >is it ok???!!!???
    It's okay, but you don't really need the second dimension.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  4. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM