is there anything similar to Java's string 'charAt()' Method in C?

后端 未结 3 1885
清酒与你
清酒与你 2021-01-22 15:07

I\'m trying to convert a piece of code from Java to C and I got stuck here, trying to get a character at each position.

char ch;

line += \' \';
    while (pos          


        
3条回答
  •  我在风中等你
    2021-01-22 15:45

    You can get a character at specific position in this way

    char str[] = "Anything";
    printf("%c", str[0]);
    

    but when you have a pointer array:

    char* an_array_of_strings[]={"balloon", "whatever", "isnext"};
    cout << an_array_of_strings[1][2] << endl;
    

    If you need to change the strings use

    char an_array_of_strings[][20]={"balloon", "whatever", "isnext"};
    cout << an_array_of_strings[1][2] << endl;
    

    source: here

提交回复
热议问题