LINUX.ORG.RU

История изменений

Исправление MOPKOBKA, (текущая версия) :

Gentooshnik, а в принципе и в С можно, я сейчас описание твоей функции symbol прочел.

$ cat main.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char *a = "gento", *b = "slackware";

int main() {
	struct BINDVAR *i;
	char buf[128];

	for(;;) {
		printf("Input name: ");
		if(scanf("%s", buf) <= 0) return 0;
		printf("Hello, ");
		if(i = find_sym(buf)) {
			if(!strcmp(i->type, "pointer to char")) {
				puts(*(const char**)i->p);
			}
		} else {
			puts(buf);
		}
		
	}
}
$ bash build.sh
$ ./a.out 
Input name: a
Hello, gento

Input name: b
Hello, slackware

Input name: f
Hello, f

Input name: 3
Hello, 3

Input name: -123
Hello, -123

Input name: $ 
$ 
$ wc -l build.sh buildscr/*
   7 build.sh
  20 buildscr/begin.txt
   9 buildscr/end.c
  13 buildscr/end.sh
  49 итого
$ 

Символы вытягиваются автоматически.

Исправление MOPKOBKA, :

Gentooshnik, а в принципе и в С можно, я сейчас описание твоей функции symbol прочел.

$ cat main.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char *a = "gento", *b = "slackware";

int main() {
	struct BINDVAR *i;
	char buf[128];

	for(;;) {
		printf("Input name: ");
		if(scanf("%s", buf) <= 0) return 0;
		printf("Hello, ");
		if(i = find_sym(buf)) {
			if(!strcmp(i->type, "pointer to char")) {
				puts(*(const char**)i->p);
			}
		} else {
			puts(buf);
		}
		
	}
}
$ bash build.sh
$ ./a.out 
Input name: a
Hello, gento
a
Input name: b
Hello, slackware
b
Input name: f
Hello, f
f
Input name: 3
Hello, 3
3
Input name: -123
Hello, -123
-123
Input name: $ 
$ 
$ wc -l build.sh buildscr/*
   7 build.sh
  20 buildscr/begin.txt
   9 buildscr/end.c
  13 buildscr/end.sh
  49 итого
$ 

Символы вытягиваются автоматически.

Исправление MOPKOBKA, :

Gentooshnik, а в принципе и в С можно, я сейчас описание твоей функции symbol прочел.

$ cat main.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char *a = "gento", *b = "slackware";

int main() {
	struct BINDVAR *i;
	char buf[128];

	for(;;) {
		printf("Input name: ");
		if(scanf("%s", buf) <= 0) return 0;
		printf("Hello, ");
		if(i = find_sym(buf)) {
			if(!strcmp(i->type, "pointer to char")) {
				puts(*(const char**)i->p);
			}
		} else {
			puts(buf);
		}
		
		puts(buf);
	}
}
$ bash build.sh
$ ./a.out 
Input name: a
Hello, gento
a
Input name: b
Hello, slackware
b
Input name: f
Hello, f
f
Input name: 3
Hello, 3
3
Input name: -123
Hello, -123
-123
Input name: $ 
$ 
$ wc -l build.sh buildscr/*
   7 build.sh
  20 buildscr/begin.txt
   9 buildscr/end.c
  13 buildscr/end.sh
  49 итого
$ 

Символы вытягиваются автоматически.

Исправление MOPKOBKA, :

Gentooshnik, а в принципе и в С можно, я сейчас описание твоей функции symbol прочел.

$ cat main.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char *a = "gento", *b = "slackware";

int main() {
	struct BINDVAR *i;
	char buf[128];

	for(;;) {
		printf("Input name: ");
		if(scanf("%s", buf) <= 0) return 0;
		printf("Hello, ");
		if(i = find_sym(buf)) {
			if(!strcmp(i->type, "pointer to char")) {
				puts(*(const char**)i->p);
			}
		} else {
			puts(buf);
		}
		
		puts(buf);
	}
}
$ bash build.sh
$ ./a.out 
Input name: a
Hello, gento
a
Input name: b
Hello, slackware
b
Input name: f
Hello, f
f
Input name: 3
Hello, 3
3
Input name: -123
Hello, -123
-123
Input name: $ 
$ 
$ wc -l build.sh buildscr/*
   7 build.sh
  20 buildscr/begin.txt
   9 buildscr/end.c
  13 buildscr/end.sh
  49 итого
$ 

Исходная версия MOPKOBKA, :

$ cat main.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char *a = "gento", *b = "slackware";

int main() {
	struct BINDVAR *i;
	char buf[128];

	for(;;) {
		printf("Input name: ");
		if(scanf("%s", buf) <= 0) return 0;
		printf("Hello, ");
		if(i = find_sym(buf)) {
			if(!strcmp(i->type, "pointer to char")) {
				puts(*(const char**)i->p);
			}
		} else {
			puts(buf);
		}
		
		puts(buf);
	}
}
$ bash build.sh
$ ./a.out 
Input name: a
Hello, gento
a
Input name: b
Hello, slackware
b
Input name: f
Hello, f
f
Input name: 3
Hello, 3
3
Input name: -123
Hello, -123
-123
Input name: $ 
$ 
$ wc -l build.sh buildscr/*
   7 build.sh
  20 buildscr/begin.txt
   9 buildscr/end.c
  13 buildscr/end.sh
  49 итого
$