【发布时间】:2020-02-22 08:31:25
【问题描述】:
我使用 c++ 创建了以下代码,但无法将其更改为 c。我尝试使用 c 在末尾显示输出列表但无法获取列表。我需要 c 语言代码用于以下 c++ 中的编码。请帮助我。
#include<iostream>
#include<string.h>
using namespace std;
int main(){
int num;
int state;
int a,b,data[num];
string element[2];
cout<<"Enter amount data: ";
cin>>num;
for(a=0;a<num;a++){
cout<<"Enter state: ";
cin>>state;
if(state==3){
element[0]="A";
} else if(state==10){
element[1]="B";
}
}
cout<<"Elements are: ";
for(b=0;b<num;b++){
cout<<" "<<element[b];
}
}
我尝试使用数组但无法获取列表输出
#include<stdio.h>
#include<string.h>
int main(){
int num;
int state;
int a,b,data[num];
char str[];
printf("Enter amount data: ");
//cin>>num;
scanf("%d",num);
for(a=0;a<num;a++){
printf("Enter state: ");
//cin>>state;
printf("%d",state);
if(state==3){
*str[0]="A";
} else if(state==10){
*str[1]="B";
}
}
printf("Elemets are: ");
for(b=0;b<num;b++){
puts(*str[b])
}
}
【问题讨论】:
-
"使用 c++ 但无法将其更改为 c" - 不 - 但为什么呢?不是很完美吗?
-
您是否遇到特定错误?
-
首先将编译器的警告级别设置为高级别(例如 gcc -Wall ...),然后修复所有警告。 BTW:请注意 C++ 版本有错误
标签: c++ c arrays string for-loop