Thread: string matrix into single string

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    12

    string matrix into single string

    [code]Ok, so i have to convert this matrix into a single line of characters. For example: If i enter {XXXYYY}, i convert it into a matrix {XXX}{YYY}. i need to change it back so i can add another element to the end of the string XXXYYYY and convert it again into a matrix, without showing the first element of it like {XXY}{YYY}. How do i do that?

    Code:
    for(i=0;i<size;i++)
                {
                    aminoacidos[x][y]=nucleotideos[i];
                    y++;
                    if (y==3)
                    {
                        y=0;
                        x++;    
                    }
                }
                for (i=0; i<((size)/3); i++) {
                    printf("%s\n",aminoacidos[i]);
                }
                if (nucleotideos[size-1]=='a') 
                {
                    strcat(nucleotideos, "a");
                }
                if (nucleotideos[size-1]=='t') 
                {
                    strcat(nucleotideos, "t");
                }
                if (nucleotideos[size-1]=='c') 
                {
                    strcat(nucleotideos, "c");            
                }
                if (nucleotideos[size-1]=='g') 
                {
                    strcat(nucleotideos, "g");        
                }
                for(i=1;i<size+1;i++)
                {
                    aminoacidos[x][y]=nucleotideos[i];
                    y++;
                    if (y==3)
                    {
                        y=0;
                        x++;    
                    }
                }
                for (i=1; i<((size+1)/3); i++) {
                    printf("%s\n",aminoacidos[i]);
                }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    In a one dim array, matrix elements are accessed like this matrix[ x * cols + y]. If you make a copy of the matrix entering elements with this formula it will work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-06-2010, 11:45 AM
  2. get single character from string
    By deltaxfx in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 01:21 PM
  3. single-string to char
    By FoodDude in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2005, 03:23 PM
  4. String to a single char
    By Thumper333 in forum C Programming
    Replies: 15
    Last Post: 11-15-2004, 10:54 PM
  5. How to strcopy a single character from a string
    By Stuu in forum C++ Programming
    Replies: 8
    Last Post: 04-18-2002, 01:45 AM

Tags for this Thread