1 year ago

#358756

test-img

Gaurav Panchanan

How to declare a variable using string concatenation and use that variable to print and integer defined as variable in C?

Getting output as 0 instead of defined value

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char *val;  
char MODE_VAR[1000]="MODE0";
int MODE0_SENSE=9;

val= strcat(MODE_VAR,"\_SENSE");
printf("String value = %s, Int value = %d\\n", MODE_VAR, atoi(val));

    return 0;

}

I get output as String value = MODE0_SENSE, Int value = 0

I would like to get: String value = MODE0_SENSE, Int value = 9

What is wrong in the code and how to fix?

c

string

strcat

atoi

0 Answers

Your Answer

Accepted video resources