the BBS Xchange
the BBS Xchange

  • C String

    From Areacode@VERT/THEWASTE to All on Sat Jul 16 15:52:00 2011
    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 Sat Jul 16 18:50:19 2011
    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