Thread: anyone knows..??!!

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    3

    Question anyone knows..??!!

    So basically I was new in c
    Anyone know how to make string we input become like this:
    Ex: input: abcq de ghisdz
    The output is:
    a d g
    b e h
    c i
    q s
    d
    z
    Like that... can someone help me with what function or what can be like that.
    i have try but the out put is
    abcq
    de
    ghisdz

    please someone help
    thx~

  2. #2
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    If you have split the input cstring on space to get three "tokens" then that's half the battle.

    Now look at your tokens. Three cstrings. How would you use a loop to get first letters in the first iteration, second letters in second iteration...?

  3. #3
    Registered User
    Join Date
    Oct 2016
    Posts
    3
    Quote Originally Posted by Xupicor View Post
    If you have split the input cstring on space to get three "tokens" then that's half the battle.

    Now look at your tokens. Three cstrings. How would you use a loop to get first letters in the first iteration, second letters in second iteration...?
    dude thx.. but now I have another problem... there's symbols on empty array @@

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Can you please post code of your attempt?

  5. #5
    Registered User
    Join Date
    Oct 2016
    Posts
    3
    Quote Originally Posted by whiteflags View Post
    Can you please post code of your attempt?
    cpp.sh/7z2yt
    Code:
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    		char in[30];
    		char in2[30];
    		char inx;
    		int x,y,z,a,b,c;
    
    		printf ("Input Word : ");
    		scanf("%s",&in);fflush(stdin);
    		printf("Input Word 2 : ");
    		scanf("%s",&in2);fflush(stdin);
    		x=strlen(in);
    		y=strlen(in2);
    		if (x==y)
    		{
    			for (z=0;z<=x || z<=y;z++)
    			{
    				printf("%c %c",in[z],in2[z]);
    				printf("\n");
    			}
    
    		}
    		else
    		{
    			for (z=0,a=0;z<=30,a<=30;z++,a++)
    			{
    				printf("%c %c\n",in[z],in2[a]);
    			}
    		}
    		getchar();
    		return 0;
    }
    Last edited by Salem; 10-24-2016 at 02:08 AM. Reason: Inlined pastebin lazyness

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > anyone knows..??!!
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread