Problem solved

I asked earlier for help for strcpy. I finally realised the problem but now I have an interesting issue. During the string copy process characters will go missing, dissapearing into the ether, they seem to be counted as nulls.

this is the prepared str array:

char tline[NLINES][LMAX] = {
" first 123 and now second -.1234 and you're needing this 123.456 plus one of these +123. too",
" ellen's favourites are 123.654E-2 eg exponent-form which can also be -54321E-03 or this +432e2",
" I'll prefer numbers like ftml-dec +.1234567e+05 or fmt2-dec -765.3245 or fmtl-int -837465 or ",
" even fmt2-int -19283746 which make us think of each state's behavior for +3 or even +3471 states ",
};

and this is the result (the [] represent the nulls):

first 123 and now seccnd -.123[][][][]d you're [][][]ding this 123.456 plus one of these +123. too ellen's favourites arr 123.654[][][] eg expon[][][][]form

and so on.

Does anyone know how I can fix this fractured problem?


Last edited on
Really?

I rather that your code is fractured. What have you got??
I realize that the sentences make no sense, they're only test words and numbers to be plugged into the program and such.

I need it however to come out as pure as it was.
I'm saying please post your code, so we can see how you are using the strcpy function.

Personally I know of no missing characters issues with strcpy,
although I'm prepared to stand corrected.
alright, I have
tline[][] as you know. I also have,
line[]

for(int i=0; i<NLINES; i++)
strcpy(line,tline[i]);

this is the loop
This code works fine.
(Note that we have only one line array - and we keep re-using it)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#define LMAX 256
#define NLINES 10

int main()
{
    char tline[NLINES][LMAX] = {
    " first 123 and now second -.1234 and you're needing this 123.456 plus one of these +123. too",
    " ellen's favourites are 123.654E-2 eg exponent-form which can also be -54321E-03 or this +432e2",
    " I'll prefer numbers like ftml-dec +.1234567e+05 or fmt2-dec -765.3245 or fmtl-int -837465 or ",
    " even fmt2-int -19283746 which make us think of each state's behavior for +3 or even +3471 states ",
    };

    char line[LMAX];

    for(int i=0; i<NLINES; i++) 
    {

        strcpy(line,tline[i]);
    }
}


If we want to copy the whole of the tline array to another one,
we would make the line array the same size as the tline array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define LMAX 256
#define NLINES 10

int main()
{
	    
    
    char tline[NLINES][LMAX] = {
    " first 123 and now second -.1234 and you're needing this 123.456 plus one of these +123. too",
    " ellen's favourites are 123.654E-2 eg exponent-form which can also be -54321E-03 or this +432e2",
    " I'll prefer numbers like ftml-dec +.1234567e+05 or fmt2-dec -765.3245 or fmtl-int -837465 or ",
    " even fmt2-int -19283746 which make us think of each state's behavior for +3 or even +3471 states ",
    };

    char line [NLINES][LMAX];

    for(int i=0; i<NLINES; i++) 
    {

        strcpy(line[i],tline[i]);
    }

}  

That's helped quite a great deal. Thank you very much. Perhaps you could help me with a little bit of trouble I'm having with an IF statement?
Topic archived. No new replies allowed.