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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-24-2004, 04:03 PM
|
#1
|
Member
Registered: May 2004
Distribution: SuSe 10.0
Posts: 154
Rep:
|
having problems reading data into a C program
I am rewriting all my programs that I wrote in Java while I was in school in C and C++ so that I am comfortable writing in these languages.
My problem is that I am getting a segmentation fault in my program after I do a scanf. I am not sure what I am doing wrong. It has been about 3 years since I have programmed in C.
Here is the code:
Code:
#include <stdio.h>
int main (void)
{
int num1, num2, num3, num4;
double dub1, dub2, dub3, dub4;
char char1, char2, char3;
scanf("%d, %d, %d, %d", num1, num2, num3, num4);
printf( "%d\n", num1);
return 0;
}
I have tried debugging the program and changing the variables to pointers. None of these solutions worked. I know it must be a simple thing bukt I am missing it. Any help would be appreciated.
Hockeyfan
|
|
|
05-24-2004, 04:07 PM
|
#2
|
Member
Registered: Mar 2003
Posts: 804
Rep:
|
you need to pass the address of each of those variables.
scanf("%d, %d, %d, %d", &num1, &num2, &num3, &num4);
u said u tried pointers, i assume u mean this:
int *num1, *num2, *num3, *num4;
those pointers dont actually point into valid memory, same as in java when u do this:
my_object foo;
u have to allocate foo before u use it, same as in C/C++.
|
|
|
05-24-2004, 04:51 PM
|
#3
|
Member
Registered: May 2004
Distribution: SuSe 10.0
Posts: 154
Original Poster
Rep:
|
Thanks for the help, I knew it was something simple.
|
|
|
All times are GMT -5. The time now is 05:20 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|