• C String

    From Areacode@VERT/THEWASTE to All on Saturday, July 16, 2011 15:52:00
    Hey, I came up with this crazy idea... i want to learn to speak Danish.

    I thought that by using a program I could teach myself the first thousand
    most commonly used wrords. The problem I'm having is assinging variables
    to strings.

    I understand a string is basically an array of characters... here's
    what I first came up with...

    char danWords[200][64],engWords[200][64];
    //for loop i1 to 200
    danwords[i]="lyserød";
    engwords[i]="pink";

    I knew the above wouldn't work, but I needed a starting point. I wound
    up here, stumped...

    char danWords[200][64],engWords[200][64];
    //for loop i 1 to 200
    scanf("lyserød",&danwords[i]);
    scanf("pink",&engWords[i]);

    How would you do this? Thanks!



    ---
    þ Synchronet þ The Wastelands BBS - wastelands-bbs.net - Keeping The Tradition Alive
  • From Digital Man@VERT to Areacode on Saturday, July 16, 2011 18:50:19
    Re: C String
    By: Areacode to All on Sat Jul 16 2011 03:52 pm

    Hey, I came up with this crazy idea... i want to learn to speak Danish.

    I thought that by using a program I could teach myself the first thousand most commonly used wrords. The problem I'm having is assinging variables
    to strings.

    I understand a string is basically an array of characters... here's
    what I first came up with...

    char danWords[200][64],engWords[200][64];
    //for loop i1 to 200
    danwords[i]="lyserød";
    engwords[i]="pink";

    I knew the above wouldn't work, but I needed a starting point. I wound
    up here, stumped...

    char danWords[200][64],engWords[200][64];
    //for loop i 1 to 200
    scanf("lyserød",&danwords[i]);
    scanf("pink",&engWords[i]);

    How would you do this? Thanks!

    Do you want to use muti-byte characters (e.g. unicode)? If so, you probably want to use a wchar string instead of a char string.

    If these are static strings (not to be modified), your first idea would work if you just use a one dimensional array of pointers:

    char* danWords[200];
    char* engWords[200];

    danwords[0]="lyserød";
    engwords[0]="pink";
    danwords[1]="xxx";
    engwords[2]="etc..";

    That would work.

    What would I do? Probably use an array of structure:

    struct {
    char* eng;
    char* dan;
    } word[200];

    word[0].eng="pink";
    word[0].dan="lyserød";

    digital man

    Synchronet "Real Fact" #7:
    Synchronet was originally intended as a replacement for WWIV BBS software.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net