Does not display the string, in C

0

I'm having trouble copying string in C, this does not want to work.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count;
    char str1[20] = "Hello World", str2[20];
    for(count = 0; str1[count]!='
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count;
    char str1[20] = "Hello World", str2[20];
    for(count = 0; str1[count]!='%pre%'; count++)
        str2[count] = str1[count];
    str2[count] = '%pre%';
    printf("%c%", str2[count]);
    system("pause");
    return 0;
}
'; count++) str2[count] = str1[count]; str2[count] = '%pre%'; printf("%c%", str2[count]); system("pause"); return 0; }

I have tried with% c, and% s, and with braces in, but nothing appears on the screen,% s appears (null), I know there is the option to use strcpy.

    
asked by anonymous 17.05.2015 / 19:28

2 answers

1

You need to

printf("%s\n", str2);

str2[count] is a character, specifically the '%code%' you just put there.

    
17.05.2015 / 19:32
1

If only one character of the string is to be displayed, it is "printf ("% c ", str2 [n])". But if you want to display all the text in the array it is "printf ("% s ", str2)".

    
09.07.2015 / 16:48