0

hello

i have the following

char *b2b_data_Out[1]={"0"};

The number "0" can change. I have a loop which goes round, and i have an integer value which i am going to use to change the above "0" into whatever value i need

Question - How do i assign my integer value to the above variable?

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Narue
0

My first question is why are you using an array of 1? There's no benefit to using an array if it only has one element.

>How do i assign my integer value to the above variable?
Presumably you're asking how do you convert an integer into a string. Here's an example that should fit into your code, but I'm making a few assumptions because your array is somewhat silly. Rather, I simply changed it to an array of char that can hold the string representation of an integer:

#include <stdio.h>

#define INT_DIGIT 21 /* Supports 64-bit int */

int main ( void )
{
  char b2b_data_Out[INT_DIGIT];
  int x;

  printf ( "Enter a value: " );
  fflush ( stdout );

  if ( scanf ( "%d", &x ) == 1 ) {
    sprintf ( b2b_data_Out, "%d", x );
    puts ( b2b_data_Out );
  }

  return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.