How to iterate over a string in C?

前端 未结 13 1309
花落未央
花落未央 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 06:57

    Just change sizeof with strlen.

    Like this:

    char *source = "This is an example.";
    int i;
    
    for (i = 0; i < strlen(source); i++){
    
        printf("%c", source[i]);
    
    }
    

提交回复
热议问题