why tell core dumped?
I am a new .I write a program.I use cc to complier it.
when i run it,it tell me "core dumped"?
who can tell me the reason?
the program as follow:
main()
{
char *a;
printf("please input your name:");
scanf("%s",a);
printf("\n");
printf("%s",a);
}
The crux of your problem is that a is a pointer to char, but it doesn't point to anything. You don't have a place to store your data when you read it in.
Your scanf statement is also very dangerous. It will allow any size string to be read. You need to make sure that your string will fit in the buffer that you allocate.
We are supposed to say "int main()" these days. And, if you're going to return from main, pass a return code. It will become your exit code.
You really should have a \n at the end of your last printf. Your code is legal without it, but you may not be able to see the output because your prompt may overwrite it. That is a hard bug to find.
Here is a legal program that is closest to your code:
First of all,thank you very much.
All you said that I have understand.
I am a newer.Could you recommend some books about c progra in
unix.
thank you for you help
I too am learning C...I have benefitted from a couple of books..
C Primer Plus Synopsis
The Waite Group's C Primer Plus, Third edition, presents the ANSI C standard beginning with a discussion of the fundamentals of C programming and then continues on to illustrate real-world C programming concepts and techniques. The Waite Group's C Primer Plus, Third Edition, is jam-packed with hundreds of sample programs, challenging yet humorous examples, hints and quizzes. Get the latest information on migrating from C to C++ and find out what will change with the release of the new C ANSI/ISO standard. Learn the mechanics of C programming and how to create programs that are easy to read, debug and update using real-world, easy-to-follow examples.
and
The C Programming Language by Kernighan & Rictchie (this is said to be the C Bible. It makes for a great reference book and a good supplement to the primer book that I use.)
Hi 2 all,
i have had AIX 7.2
:/# /usr/IBMAHS/bin/apachectl -v
Server version: Apache/2.4.12 (Unix)
Server built: May 25 2015 04:58:27
:/#:/# /usr/IBMAHS/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_worker_module (static)
... (3 Replies)
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
Hi,
thanks to a precedent post, and thanks to the reply of derekludwig of the forum, I have convert my first awk command as :
test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL
awk -f findstring.awk test.txt > textreturn.txtfindstring.awk is :
BEGIN{ SLENGTH = 3 }
{
... (3 Replies)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi,
I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone.
And its not dumping core if we run the script using "/bin/sh" instead of "ksh"
Can some body please help me how to resolve this issue.
... (9 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
Hai!
i am working on Digital UNIX V3.2c Work station, my program uses Pro*C, C and X-Motif calls. i am facing problem while running application saying "Illegal Instruction Core Dumped".
debugger dbx shows error at a line which shows "noname". when commenting large portion of the code it runs... (1 Reply)