This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How recieve string into controller

Hi everybody!

I work with Keil C251 uVision2.
in my programm i want to recieve string into controller. i have an array of characters incom[20], which i use as a buffer for recieving string. i recieve current byte into variable bufIn and then replace it into my array:

 1.  	strcat(incom, bufIn);

or
 2.     incom[i] = bufIn;
	i++;
in 2 cases before (1) & (2) i test with my routine Print(unsigned char) and can see that every next byte is recieved into bufIn variable, and after (1) & (2) i can see that byte is stored into the next byte of incom[] array.
But after recieving the whole string while testing array:
for(i = 0; i < 20; i++)
     Print(incom[i]);
i can see the empty string with only the last recieved byte on the last place, for example: " a".
If anybody can help me to recieve the whole string?
And else. Why i can't create any array of characters more than 20 symbols?
Thaks.
Gennady.

Parents
  • >1. strcat(incom, bufIn);
    >2. incom[i] = bufIn;
    > i++;

    How you declare "bufIn" ?

    Function strcat need "pointer to char" (not a "char") as second parameter.
    This must be NULL-terminated string with length less than unused area in "incom" !!!
    So, your code probably have a bug or bug's.


    I think this is not C251-specific question.



    >Why I can't create any array of
    >characters more than 20 symbols?

    Why not ? No problem.

    char       Buf[32]; // default memory space
    // or
    char idata Buf[64]; 
    // or
    char xdata Buf[1000]; 
    // or
    char edata Buf[32]; // C251-native addressing
    

    (You can receive error from linker if no free space in memory).

    Your question unclear,
    so no ideas because no source code.




Reply
  • >1. strcat(incom, bufIn);
    >2. incom[i] = bufIn;
    > i++;

    How you declare "bufIn" ?

    Function strcat need "pointer to char" (not a "char") as second parameter.
    This must be NULL-terminated string with length less than unused area in "incom" !!!
    So, your code probably have a bug or bug's.


    I think this is not C251-specific question.



    >Why I can't create any array of
    >characters more than 20 symbols?

    Why not ? No problem.

    char       Buf[32]; // default memory space
    // or
    char idata Buf[64]; 
    // or
    char xdata Buf[1000]; 
    // or
    char edata Buf[32]; // C251-native addressing
    

    (You can receive error from linker if no free space in memory).

    Your question unclear,
    so no ideas because no source code.




Children