S
streamkid
hello..
my code is this:
//test.cpp
#include <cstdio>
int main(void)
{
int NP;
char *tmp;
FILE *fin;
fin = fopen("test.in", "r");
fscanf(fin, "%d", &NP);
printf("%d\n", NP);
fscanf(fin, "\n%s", tmp);
printf("%s\n", tmp);
return 1;
}
test.in is this:
3
alex
output is:
3
(null)
why isn't fscanf reading alex??
(after 3 there is only one new-line character)...
i 'm confused.. that used to work somewhen :s
another example that doesn't work:
//test.cpp
#include <cstdio>
int main()
{
char *tmp;
FILE *fin;
fin = fopen("test.in", "r");
fscanf(fin, "%s", tmp);
printf("%s\n", tmp);
fclose(fin);
return 1;
}
test.in contains:
alex
output is:
lookup 0x08048000 0x000001d4 -> 0x4012d000 0x000448b0 /1 printf
lookup 0x08048000 0x000001e4 -> 0x4012d000 0x00054650 /1 fclose
Segmentation fault.
and last "app" from gdb:
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i486-slackware-linux"...Using host
libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /home/alex/test
lookup 0x08048000 0x000001d4 -> 0x4012d000 0x000448b0 /1 printf
lookup 0x08048000 0x000001e4 -> 0x4012d000 0x00054650 /1 fclose
Program received signal SIGSEGV, Segmentation fault.
0x40008136 in do_lookup_x () from /lib/ld-linux.so.2
(gdb) q
The program is running. Exit anyway? (y or n) Please answer y or n.
huh? :s any explanations?
my code is this:
//test.cpp
#include <cstdio>
int main(void)
{
int NP;
char *tmp;
FILE *fin;
fin = fopen("test.in", "r");
fscanf(fin, "%d", &NP);
printf("%d\n", NP);
fscanf(fin, "\n%s", tmp);
printf("%s\n", tmp);
return 1;
}
test.in is this:
3
alex
output is:
3
(null)
why isn't fscanf reading alex??
(after 3 there is only one new-line character)...
i 'm confused.. that used to work somewhen :s
another example that doesn't work:
//test.cpp
#include <cstdio>
int main()
{
char *tmp;
FILE *fin;
fin = fopen("test.in", "r");
fscanf(fin, "%s", tmp);
printf("%s\n", tmp);
fclose(fin);
return 1;
}
test.in contains:
alex
output is:
lookup 0x08048000 0x000001d4 -> 0x4012d000 0x000448b0 /1 printf
lookup 0x08048000 0x000001e4 -> 0x4012d000 0x00054650 /1 fclose
Segmentation fault.
and last "app" from gdb:
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i486-slackware-linux"...Using host
libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /home/alex/test
lookup 0x08048000 0x000001d4 -> 0x4012d000 0x000448b0 /1 printf
lookup 0x08048000 0x000001e4 -> 0x4012d000 0x00054650 /1 fclose
Program received signal SIGSEGV, Segmentation fault.
0x40008136 in do_lookup_x () from /lib/ld-linux.so.2
(gdb) q
The program is running. Exit anyway? (y or n) Please answer y or n.
huh? :s any explanations?