How to iterate over a string in C?

前端 未结 13 1311
花落未央
花落未央 2020-11-28 06:43

Right now I\'m trying this:

#include 

int main(int argc, char *argv[]) {

    if (argc != 3) {

        printf(\"Usage: %s %s sourcecode inpu         


        
13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 07:16

    sizeof(source) returns the number of bytes required by the pointer char*. You should replace it with strlen(source) which will be the length of the string you're trying to display.

    Also, you should probably replace printf("%s",source[i]) with printf("%c",source[i]) since you're displaying a character.

提交回复
热议问题