【发布时间】:2023-03-10 07:30:02
【问题描述】:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void)
{
int menuswitch=1;
int amountofstudents;
int fname[50];
int lname[50];
int grade[50];
int i;
char studentinfo[100];
printf("Enter Amount of Students: ");
scanf("%d", &amountofstudents);
for (i=0;i<amountofstudents;i++)
{
gets(studentinfo);
strcpy(fname[i], strtok(studentinfo, " "));
strcpy(lname[i], strtok(NULL, " "));
strcpy(grade[i], strtok(NULL, " "));
}
好吧,需要一点使用 strtok。我正在尝试存储输入字符串的片段以供以后排序。我正在考虑使用 strtok 来断开字符串,然后将每个部分放在相应的数组中。然而,每次我尝试时,我都会在 Visual Studios 中收到一个错误,说访问冲突。提前感谢您的帮助
错误是
First-chance exception at 0x5120F7B3 (msvcr110d.dll) in Lab 2.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x5120F7B3 (msvcr110d.dll) in Lab 2.exe: 0xC0000005: Access violation reading location 0x00000000.
输入将是
FirstName Lastname 80(Grade)
【问题讨论】:
-
您能否提供一些导致此问题的示例输入?也许还有来自调试器的调用堆栈?
-
你为什么要将
char*复制到int*vis strcpy?