#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* getstr(int value)
{
//static char port_str[10] = {0};
char port_str[10] = {0};
switch(value)
{
case 1:
strcpy(port_str,"uart1");
break;
case 2:
strcpy(port_str,"usbmodem");
break;
}
return port_str;
}
int main(int argc, char *argv[]) {
char *p = NULL;
p = getstr(1);
printf("%s,0x%x\n",p,p);
return 0;
}
mali@mali:~/share/7600M21$ gcc main.c -o main
main.c: In function ‘getstr’:
main.c:18:2: warning: function returns address of local variable [enabled by default]
main.c: In function ‘main’:
main.c:25:2: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘char *’ [-Wformat]
mali@mali:~/share/7600M21$ ./main
+@,0xab9d42e0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* getstr(int value)
{
static char port_str[10] = {0};
//char port_str[10] = {0};
switch(value)
{
case 1:
strcpy(port_str,"uart1");
break;
case 2:
strcpy(port_str,"usbmodem");
break;
}
return port_str;
}
int main(int argc, char *argv[]) {
char *p = NULL;
p = getstr(1);
printf("%s,0x%x\n",p,p);
return 0;
}
mali@mali:~/share/7600M21$ gcc main.c -o main
main.c: In function ‘main’:
main.c:25:2: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘char *’ [-Wformat]
mali@mali:~/share/7600M21$ ./main
uart1,0x601030