![]() |
| | #1 |
| Registered User Join Date: Sep 2005
Posts: 10
| Segfaulting Distance Program Code: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[])
{
float distance; //total distance
float x[2]; //the x coordinates
float y[2]; //the y coordinates
char line[100]; //the read line
printf("What is x1?\n");
fgets(line, sizeof(line), stdin);
sscanf(line, "%f", x[0]);
/*It segfaults here*/
printf("\n\nWhat is x2?\n");
fgets(line, sizeof(line), stdin);
sscanf(line, "%f", x[1]);
printf("\n\nWhat is y1?\n");
fgets(line, sizeof(line), stdin);
sscanf(line, "%f", y[0]);
printf("\n\nWhat is y2?\n");
fgets(line, sizeof(line), stdin);
sscanf(line, "%f", y[1]);
distance = sqrt(((x[1] - x[0]) * (x[1] - x[0])) + ((y[1] - y[0]) * (y[1] - y[0])));
printf("\n%f", distance);
system("PAUSE");
return 0;
}
|
| radiohead is offline | |
| | #2 |
| Registered User Join Date: Apr 2005
Posts: 134
| change this Code: sscanf(line, "%f", x[0]); Code: sscanf(line, "%f", &x[0]); |
| nkhambal is offline | |
| | #3 |
| Registered User Join Date: Sep 2005
Posts: 10
| ah, thanks |
| radiohead is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BOOKKEEPING PROGRAM, need help! | yabud | C Programming | 3 | 11-16-2006 11:17 PM |
| Can someome help me with a program please? | WinterInChicago | C++ Programming | 3 | 09-21-2006 10:58 PM |
| I need some help with my program please. | agentxx04 | C Programming | 9 | 09-26-2004 07:51 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |