How to iterate over a string in C?

前端 未结 13 1299
花落未央
花落未央 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:15

    • sizeof(source) is returning to you the size of a char*, not the length of the string. You should be using strlen(source), and you should move that out of the loop, or else you'll be recalculating the size of the string every loop.
    • By printing with the %s format modifier, printf is looking for a char*, but you're actually passing a char. You should use the %c modifier.

提交回复
热议问题