问题描述
- c语言编译 出现error C2061 和error C2059
-
不知道为什么一直出现说我标识符有问题的提示,我看了下以前编的程序,好像也是这样写法的啊,不知这次怎么会这样。求各位大神相助。
#include <stdio.h> #include <stdlib.h> struct Jihe{ char nodeSet; struct Jihe* next; }; bool Initiate(struct Jihe** head){ *head = (struct Jihe*)malloc(sizeof(struct Jihe)); (*head)->next = NULL; return 1; } bool RecordSet(struct Jihe* head,char text[]){ struct Jihe* set = head; int i = 0; while(text[i] != ''){ set->next = (struct Jihe*)malloc(sizeof(struct Jihe)); set->next->nodeSet = text[i]; i++; set = set->next; } set->next = NULL; RankSet(&head); return 1; } bool GetAnd(struct Jihe* head1,struct Jihe* head2,struct Jihe** result){ struct Jihe *set1 = head1,*set2 = head2,*set3 = *result; while(set1->next != NULL && set1->next->next != NULL){ set3->next = (struct Jihe*)malloc(sizeof(struct Jihe)); set3->next->nodeSet = set1->next->nodeSet; set3 = set3->next; set1 = set1->next; } while(set2->next->next != NULL){ set3->next = (struct Jihe*)malloc(sizeof(struct Jihe)); set3->next->nodeSet = set2->next->nodeSet; set3 = set3->next; set2 = set2->next; } set3->next = NULL; RankSet(result); return 1; } bool GetCross(struct Jihe** head1,struct Jihe** head2){ return 1; } bool GetDiffer(struct Jihe** head1,struct Jihe** head2){ return 1; } bool RankSet(struct Jihe** head){ char rankSet[20] = {0}; int i = 0 ,j = 0,len = 0;//len记录集合大小 int small = 0, move;//move是用来删除元素的; char temp; struct Jihe* set = *head; struct Jihe* newSet = NULL; if(set == NULL){ printf("空链表 "); return 0; } while(set->next != NULL && set->next->next != ''){ rankSet[i] = set->next->nodeSet; set = set->next; len++; } for(i = 0;i < len; i++){ for(j = i+1;j < len;j++){ //删除子串中相同的元素 if(rankSet[i] == rankSet[j]){ //当这个元素为最后一个时,将终止符前移 for(move = j; move <= len-1; move++){ rankSet[move] = rankSet[move+1]; } len--; } if((rankSet[small] > rankSet[j]) && rankSet[j] != '' ) small = j; } if(rankSet[small] == '') break; temp = rankSet[small]; rankSet[small] = rankSet[i]; rankSet[i] = temp; } newSet = (struct Jihe*)malloc(sizeof(struct Jihe)); head = &newSet; for(i = 0;i < len;i++){ newSet->next = (struct Jihe*)malloc(sizeof(struct Jihe)); newSet->next->nodeSet = rankSet[i]; newSet = newSet->next; } newSet->next = NULL; return 1; } bool GetSet(struct Jihe* head,char nowSet[]){ struct Jihe*p = head; int i = 0; nowSet = {0}; while(p->next != NULL && p->next->next != NULL){ nowSet[i] = p->next->nodeSet; p = p->next; i++; } return 1; } void main(){ struct Jihe *set1; struct Jihe *set2; struct Jihe *result; char text[20] = {0}; Initiate(&set1); Initiate(&set2); Initiate(&result); printf("Set1 = :"); scanf("%s",text); RecordSet(set1,text); printf("Set2 = "); scanf("%s",text); RecordSet(set2,text); printf("Set1 ∪ Set2 = "); }
解决方案
返回类型不行。或许是c语言没有bool型(忘了到底有没有了),该为int就没事了
解决方案二:
struct Jihe{
char nodeSet;
struct Jihe* next;
};
这是C++的写法,C不能这么写。
解决方案三:
C和C++混合编程(error C2059: syntax error : 'string')
C和C++混合编程(error C2059: syntax error : 'string')
cocos2d-x error C2061
时间: 2024-09-11 04:32:51