无论我重新格式化多少次,我都会遇到各种各样的错误。最终结果将是一个程序,可以保存望远镜中的电机目标并设置坐标。任何帮助解释我在这个设置上做错了将不胜感激。这是代码:
//IDENTIFY RECEIVER OF MESSAGE / TYPE OF MESSAGE / VIEW ALL TO 1 DEVICE / VIEW SPECIFIC MESSAGE
#include "messaging.h"
#include <string.h>
#include <stdio.h>
using namespace std;
typedef struct MGR{
mess_types messagetype;
int DeviceID;
union E{
//why arte these underlined?
char INST[STRSIZE];
int codes[NBRCODES];
float coords[NBRCOORDS];
} message;
};// info;
void messager(){
MGR my_data;
my_data.messagetype = INST;
my_data.DeviceID = TECH1;
strcpy(my_data.message.INST, "GO HOME");
my_data.messagetype = CODES;
my_data.DeviceID = MOTOR1;
for (int nbr = 0; nbr < NBRCODES; nbr++){
my_data.message.codes[nbr] = nbr;
print_message(my_data);
}
}
int print_message(MGR mydata){
MGR noot;
scanf("%s", &mydata);
switch (mydata.messagetype){
case INST:
printf("Message to Device %d", noot.DeviceID);
break;
case CODES:
printf("The setup codes for device %d are: \n", noot.DeviceID);
for (int code = 0; code < NBRCODES + OFFSET; code++){
printf("%4d\t", noot.message);
}
break;
case COORDS:
printf("The setup codes for device %d are: \n", noot.DeviceID);
for (int code = 0; code < NBRCODES + OFFSET; code++){
printf("%4d\t", noot.message);
}
break;
}
printf("%c", mydata.messagetype);
return(0)
}
void Sendmessage(){
printf("This program does not work... it is under construction...");
}
以防万一:这是头文件
#include "sprint1.h"
#include <string.h>
#include <stdio.h>
#define STRSIZE 50
#define NBRCODES 200
#define NBRCOORDS 200
#define OFFSET 100
#define FACTOR 50
#define TECH1 123
#define MOTOR1 4556
void messager();
int print_message(MGR mydata);
void Sendmessage();
enum mess_types {INST, CODES, COORDS};
错误列表:https://drive.google.com/file/d/0B0CXbbHDOrweQVVvOVU1M0VRaEE/view?usp=sharing
答案 0 :(得分:0)
我假设列出的标题是&#34; messaging.h&#34;
在代码中的定义之前的标题中引用了MGR。 也许在第一次引用之前将定义移动到标题。