C precompiler define in scanf

hi there!
I am currently using something like that in my code:

1
2
  char in[100];
  scanf(" %100s",&in);


but i wanted to be able to change my buffer size without going through all my code and tried this:

1
2
3
4
#define INBUFFERSIZE 100

 char in[INBUFFERSIZE];
 scanf(" %INBUFFERSIZEs",&in);

but apprently the precompiler will not modify the contents of a " string"

is there another elegant solution to this problem, or not?

yours nafnaf
So, I am not to sure if I should be commenting since I don't know C enough to give an opinion but maybe try setting it to a variable like x and change x
Typically, something like this is what is done:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>

/* read a white space delimited string into cstr
    sz (greater than one) is the size of the character buffer 
    therefore, allow no more than sz-1 characters */
int read_str( char* cstr, size_t sz )
{
    char format[16] ;
    sprintf( format, "%%%ds", sz-1 ) ;
    return scanf( format, cstr ) ;
}

#define INBUFFERSIZE 100

int main()
{
    char in[INBUFFERSIZE] ;
    read_cstr( in, INBUFFERSIZE ) ;
    puts(in) ;
}
ah thyvm ^^
Topic archived. No new replies allowed.