-1
Ich möchte eine Funktion erstellen, die Gleichung (String) wie ax^2+bx+c=0
(ex: "3x^2+8=0"
) erhält und a
, b
, c
Parameter erhalten.Wie erhält man ABC-Parameter aus der quadratischen Gleichung?
Hier ist mein Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STR_LEN 25
void getABC(char str[]);
int a=0, b=0, c=0;
int main(void)
{
char equation[STR_LEN]={0};
printf("Enter an equation:\n");
fgets(equation, STR_LEN, stdin);
equation[strcspn(equation, "\n")]=0;
getABC(equation);
return 0;
}
void getABC(char str[])
{
// how to get a, b and c?
}
'sscanf' würde hier von Nutzen sein. –
Bitte beantworten Sie wie ausgewählt, wenn es Ihre Anfrage gelöst hat. –
In Ihrer Frage ist die Beispieleingabe '3x^2 + 8 = 0' Ohne ax^2 + bx + c, ohne b, ist es richtig, oder Sie haben das versehentlich geschrieben? –