我用Visual C++ 2005
自己測試時並沒有問題
但是上傳後卻一直出現RE的錯誤
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Code 7
struct Input{
char *text;
struct Input *link;
};
struct Input* getNode(void);
void Print_text(struct Input *);
void subtract_Code(int code, char *Str);
int main(void){
char *input;
struct Input *Input_Node = NULL;
struct Input **Now;
input = (char *) malloc(sizeof(char *));
Now = (struct Input **) malloc(sizeof(struct Input *));
for(Now = &Input_Node; gets(input) != NULL; Now = &((*Now)->link)){
*Now = getNode();
strcpy((*Now)->text, input);
subtract_Code(Code, (*Now)->text);
}
Print_text(Input_Node);
return 0;
}
struct Input* getNode(void){
struct Input *temp;
temp = (struct Input *) malloc(sizeof(struct Input));
temp->text = (char *) malloc(sizeof(char *));
temp->link = NULL;
return temp;
}
void subtract_Code(int code, char *Str){
int len = strlen(Str);
int i;
for(i = 0; i < len; ++i){
Str[i] = Str[i] - code;
}
}
void Print_text(struct Input *Now){
for(; Now != NULL; Now = Now->link){
puts(Now->text);
}
}
我改了程式如下
簡單多...又對了=.=
我一直以為這裡的程式多測資
是指
一次輸完所有資料後
再輸出...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Code 7
void subtract_Code(int code, char *Str);
int main(void){
char *input;
input = (char *) malloc(sizeof(char *));
while(scanf("%s", input) != EOF){
subtract_Code(Code, input);
printf("%s\n", input);
}
return 0;
}
void subtract_Code(int code, char *Str){
int len = strlen(Str);
int i;
for(i = 0; i < len; ++i){
Str[i] = Str[i] - code;
}
}