c - 警告 : assignment makes pointer from integer without a cast [enabled by default]

标签 c scheduling strtok

我收到此警告

warning: assignment makes pointer from integer without a cast [enabled by default].

我尝试在其他线程上阅读有关它的内容,但我无法弄清楚发生了什么。这是代码

#include<stdio.h>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum,index = 0;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
char type[5];
char str[50];
char *ptr;
FILE *fp = fopen("input.txt", "r");
fgets(str, 100, fp); // reading line
ptr = strtok(str, " "); // splitting by space
int i=0;
while(ptr != NULL)
{
if(index == 0){
type = ptr;
index++;
}
else if(index == 1){
n = ptr;
remain = n;
index++;
}
else{
at[i] = (int) strtol(ptr[1], (char **)NULL, 10);
bt[i] = (int) strtol(ptr[2], (char **)NULL, 10);
rt[i] = bt[i];
i++
}
ptr = strtok(NULL, " "); // and keep splitting
}
fclose(fp);

char c[1000];
FILE *fptr;
fptr=fopen("output.txt","w");
fprintf(fptr,"%s","\n\nProcess\t|Turnaround Time|Waiting Time\n\n");

for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
fprintf(fptr,"P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);

printf();
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
fprintf(fptr,"\nAverage Waiting Time= %f\n",wait_time*1.0/n);
fprintf(fptr,"Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}

最佳答案

您应该包括string.h文件 strtok()定义于 <string.h>

更多信息here

关于c - 警告 : assignment makes pointer from integer without a cast [enabled by default],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36877023/

相关文章:

c++ - 无法停止来自 python C 扩展的 python 回调

algorithm - bool 可满足性的类调度 [多项式时间缩减] 第 2 部分

java - 日历之类的调度库java

c# - 有约束的计划

c - 在 C 中使用 strtok 解析输入

c - 找出两个日期之间的小时差?

c - 如何将ISO8601解析为time_t?

c - 包含字符串和 float 的函数,我从 main 中调用它。但错误

c - 拆分字符串以删除定界符后的所有内容

c - 下面的 while 循环有什么问题?