string matrix into single string

This is a discussion on string matrix into single string within the C Programming forums, part of the General Programming Boards category; [code]Ok, so i have to convert this matrix into a single line of characters. For example: If i enter {XXXYYY}, ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    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, 10:45 AM
  2. get single character from string
    By deltaxfx in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 12: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, 09: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21