Hi. I'm new to C, so I have probably made an elementary mistake in my code.
I am trying to make a program for finding roots of a quadratic equation, using if and else, but first I'm trying to get used to using the sscanf function which I have never encountered before. After compiling I am getting an error in line 12: parse error before string constant

Can anybody shed some light on this for me please?

Heres my program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int a, b, c;
float real_root;

int main (int argc, char* argv[])
{
	printf ("Enter the co-efficients a, b, and c : ");
	
	sscanf (argv[1] "%d %d %d", &a, &b, &c);
	
	real_root = (b*b)+4*a*c;
	
	if (real_root < 0)
	{
		printf("No Real Roots\n");
		return (0);
	}
	
}

That particular one is a simple coma been missing. sscanf (argv[1], "%d %d %d", &a, &b, &c); Did you forget to return in main?

[Edit:] By the way argv[1] should be replaced by another variable place holder if you intend to ask the user for some input and after you read that input you use sscanf() for parsing it.
argv[1] is input from the command line at the start of the program.

Your variable real_root should be b*b - 4*a*c.(Notice the minus sign) Most of the time we call it a "Discriminant", but hey what's in a name.
You might also want to check http://www.daniweb.com/code/snippet980.html although that's in C#.

thanks for your help! I can now get properly started!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.