LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2005, 04:22 PM   #16
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43

Code:
17:20 aluser@alf:~/C$ cat blah.c
#include <stdio.h>
#include <string.h>

int main()
{
        char *b;
        char login[16];

        printf("Please enter some text: ");
        scanf("%s", login);
        printf("test 1\n");

        strcpy(b, login);
        printf("test 2  %s %s\n", login, b);

        printf("%s\n", b);
        printf("test 3\n");

        return 0;
}
17:20 aluser@alf:~/C$ gcc -o blah blah.c
17:20 aluser@alf:~/C$ ./blah
Please enter some text: hello
test 1
Segmentation fault (core dumped)
you got lucky; your b happened to point somewhere valid. if you start it off as NULL or 0xffffffff, you'll get an error too.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C# convert char array to string exodist Programming 3 09-16-2008 08:06 AM
array of char pointers djgerbavore Programming 2 01-08-2005 01:59 PM
search in char array xxfunkxx Programming 2 12-12-2004 11:23 PM
char array of size 10 can read morethan 10 chars!!!!! pippet Programming 13 07-12-2004 01:44 AM
Char array to int without losing value ? Dimitris Programming 3 01-14-2004 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration