是否可以将整个结构写入文件
例:
struct date {
char day[80];
int month;
int year;
};
Run Code Online (Sandbox Code Playgroud) 尝试在我的程序的字符串数组中输入多个字符串,用于:
scanf("%80[^\r\n]", strings[i]);
fgets(string[i], MAXLEN, stdin);
还使用了自定义功能:
int getString(char s[]) {
char ch;
int i=0;
while( (ch = getchar()) != '\n' && ch != EOF ) {
s[i] = ch;
++i;
}
s[i] = '\0';
fflush(stdin);
return i;
}
Run Code Online (Sandbox Code Playgroud)
但无法输入多个字符串,每个字符串包含空格
函数gets()过去对我来说比较早,但由于它已被弃用,因此无法找到替代方案
这是使用它的地方:
int getString(char s[]) {
char ch;
int i=0;
while( (ch = getchar()) != '\n' && ch != EOF ) {
s[i] = ch;
++i;
}
s[i] = '\0';
fflush(stdin);
return i;
}
struct vechileData
{
char …Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <math.h>
struct coeff
{
int a;
int b;
int c;
};
struct roots
{
double r1;
double r2;
};
void calculateRoots(struct coeff*, struct roots*);
int main(int argc, char const *argv[])
{
struct coeff *c;
struct roots *r;
c = NULL;
r = NULL;
c->a = 10;
c->b = 20;
c->c = 30;
calculateRoots(c,r);
printf("The roots are : %lf & %lf\n", r->r1, r->r2);
return 0;
}
void calculateRoots(struct coeff *cef, struct roots *rts)
{
rts->r1 = (-(cef->b) + …Run Code Online (Sandbox Code Playgroud)