0

I want to take n number of inputs and save it in the arrays c[] and p[] and later use them...

I have currently written this,but i'm not getting desired output

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,t,i,j,size=0;
    char s[100000];
    char c[100];
    char p[100];
    scanf("%d", &n);

    for(i=0;i<n;i++)
    {
        scanf("%c", &c[i]);
        scanf("%c", &p[i]);
    }

    for(i=0; i<n;i++)
    {
        printf("%c %c", c[i],p[i]);
    }
    return 0;
}
2
  • 1
    it doesn't work - can you show expected output when it will work? Commented Jun 8, 2014 at 10:59
  • i want it to be like 4 w r 2 9 f g q t now c should store w2fq and p should store r9gt Commented Jun 8, 2014 at 11:01

3 Answers 3

3

Considering from your second comment: "i want it to be like 4 w r 2 9 f g q t now c should store w2fq and p should store r9gt ",
you should change all the for(...) loop with for(i=0;i<n/2;i++)

Sign up to request clarification or add additional context in comments.

Comments

1

Use this

for(i=0; i<n;i++)
{
    scanf("%c %c", &c[i], &p[i]);
}

%s is for string of characters. If you want to read only one character, you should use %c.

1 Comment

program crashed by doing so
0
for(i=0;i<n;i++)
{
    scanf(" %c", &c[i]);//skip space character
    scanf(" %c", &p[i]);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.