How do I properly 'printf' an integer and a string in C?

后端 未结 3 928
遥遥无期
遥遥无期 2021-01-03 19:30

I have the following code:

char *s1, *s2;
char str[10];

printf(\"Type a string: \");
scanf(\"%s\", str);

s1 = &str[0];
s2 = &str[2];

printf(\"%s\\         


        
3条回答
  •  Happy的楠姐
    2021-01-03 20:14

    Try this code my friend...

    #include
    int main(){
       char *s1, *s2;
       char str[10];
    
       printf("type a string: ");
       scanf("%s", str);
    
       s1 = &str[0];
       s2 = &str[2];
    
       printf("%c\n", *s1);   //use %c instead of %s and *s1 which is the content of position 1
       printf("%c\n", *s2);   //use %c instead of %s and *s3 which is the content of position 1
    
       return 0;
    }
    

提交回复
热议问题