문제

I am trying to a loop packet [bytes] and to put the result into the variable, however I stucked for few hours to put it into variable.

This is what is working, just outputting it. I've tried strcat, strcpy and sprintf to put the output into a variable and no success. Suggest me please what to do, cause Im lost, thanks :)

i = 54;
do {
 printf("%c", Buffer[i]);
 i++;
} while(i != Size);
도움이 되었습니까?

해결책

One of pieces of this code should help but you have asked very unclear question and it's hard to understand what indeed you're trying to do.

BTW as you can see Buffer here is not initialized (actually all of them as others depends on Buffer. It was intent to get some data to output.

#include <stdio.h>

int main(int argc, char **argv)
{
    const int Size = 100;
    unsigned char Buffer[Size];
    unsigned char OutBuffer[Size];
    unsigned char PrnBuffer[Size*3];

    /* I have understanding you tried to output chars to OutBuffer but
       you just need to iterate OutBuffer bytes the same way... */
    int i = 54;
    int j = 0;
    do {
        sprintf(&(OutBuffer[j]), "%c", Buffer[i]);
        /* But why simply not outBuffer[j] = Buffer[i]; ?? */
        i++;
        j++;
    } while(i != Size);

    /* And now print this trash... */
    for (i = 0; i < j; ++i)
    {
        sprintf(&(PrnBuffer[i*3]), "%02x ", OutBuffer[i]);
    }
    printf("%d: %s\n", j, PrnBuffer);

    return 0;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top