c语言编程错误解析:下面是代码(跟上一个提问不一样),请问错在哪儿?为什么错了?怎么改才是正确的?

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define BUFFER_LEN 256
#define NUM_P 42
int main(void)
{
char input[BUFFER_LEN];
char *pinput = input;
char buffer[BUFFER_LEN];
double pS[NUM_P];
int index = 0;
int count = 0;
int j =0;
double zhuanhuan = 0;

printf("请输入任意天数的浮点温度值,其中6个值为一天,温度值之间用加号隔开\n:");
while((*pinput++ = getchar()) != '\n');
*(pinput-1) = '\0';
pinput = input;
while(*pinput != '\0')
{
if(count != 0 && count%5 == 0)
{
pS = (double *)malloc(sizeof(double)*index);

if(pS==NULL)
{
printf("x");
getch();
return 1;
}

strcpy(pS[j++],zhuanhuan);
zhuanhuan = 0;
}

index = 0;
while(isdigit(*(pinput)) || *pinput == '.')
buffer[index++] = *pinput++;

if(*pinput== '+'|| *pinput =='\0')
{
++count;
*pinput++;
buffer[index]='\0';
zhuanhuan += atof(buffer);
}
}
printf("%d\n",j);
if(count <5)
printf("还不到一天6个浮点温度值\n");
else
for(int k = 0; k<j; k++)
{
printf("低%d天的平均温度值是%f\n",k+1,pS[k]/6);
}

getch();
return 0;
}

第一个:
pS = (double *)malloc(sizeof(double)*index);
pS[NUM_P]是分配好内存的了,你定义的42,pS是常量,无法进行赋值操作。
你需要重新定义指针变量来操作
第二个:
strcpy()是针对字符串的,不能将浮点数拿来拷贝,你就改成:
pS[j++] = zhuanhuan;
更何况你还写的pS[j++],假如pS[]是字符串数组,strcpy()也需要字符串的指针
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-08-25
你用的是什么编的,我的怎么就可以啊,我的好像就是你要的那个结果哦,你试下吧,我也是改了你的小小的一点

#include<stdio.h>
main()
{
char str1[80],str2[80];
int i=0,j=0;
printf("输入st1的字符,并按回车结束:");
gets(str1);
printf("输入st2的字符,并按回车结束:");
gets(str2);
while(str1[i]!='\0')
{
i++;
if(str1[i]=='\0') break;
}
while(str2[j]!='\0')
{
str1[i]=str2[j];
i++;
j++;
if(str2[i]=='\0') break;
}
str1[i]='\0';
printf("%s\n",str1);
return 0;
}//这里没有符号的,不知是不是你打错了
第2个回答  2011-08-24
#include "student.h"/*头文件*/

link deletenode(link head)//链表
{
link pointer; /*节点声明*/
link Back;
char DataFile[40];//char的字符数组
int key; //整形变量key
FILE *fp = NULL;//文件操作指针,初始化为null
struct student Tmps;//student 结构体对象Tmps

printf("\nPlease input the student number that you want to delete:");//输出nPlease input the student number that you want to delete:这个语句
scanf("%d",&key);//输入一个key,也就是你要删除的节点
pointer=head; /*pointer 指针设为首节点*/
while(1)//死循环,不断执行while里面的语句
{
if(pointer->next==NULL)//如果头指针指向空
{
printf("Not Found!\n");//则输出Not Found
break;//直接跳出while循环
}

if (key == 0) /*删除首节点*/
{
pointer = head->next;//头节点的下一个节点赋值给指针pointer
head->next = pointer->next;//指针pointer的下一个节点作为头节点的下一个节点
free(pointer);//释放指针pointer
break;
}

这样可以 了吧?

该程序的主要作用是删除你输入的一个节点。
相似回答