我自己測試時並沒有顯是錯誤
但是貼上來測試時
它卻顯示出現奇怪的字元
可以請各位幫我看一下嗎?
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
struct Prime{
int num;
char Is_Prime[8];
};
struct Prime* Prime_Stack;
int main(void){
int i;
int j;
int input_num = 0;
float sqrt_root = 0.0f;
Prime_Stack = (struct Prime*) malloc(sizeof(struct Prime));
for(i = 0, input_num = 1; scanf("%d", &Prime_Stack[i].num) != EOF; ++i, ++input_num){
Prime_Stack = (struct Prime*) realloc(Prime_Stack, sizeof(struct Prime) * (input_num+1));
sqrt_root = sqrt((float) Prime_Stack[i].num);
for(j = 2; j < sqrt_root; ++j){
if(Prime_Stack[i].num % j == 0){
strcpy(Prime_Stack[i].Is_Prime, "非質數");
break;
}
else{
continue;
}
}
if(strcmp(Prime_Stack[i].Is_Prime, "非質數") == 0){
continue;
}
else if(Prime_Stack[i].num == 2){
strcpy(Prime_Stack[i].Is_Prime, "質數");
}
else{
strcpy(Prime_Stack[i].Is_Prime, "質數");
}
}
for(i = 0; i < (input_num-1); ++i){
printf("%s\n", Prime_Stack[i].Is_Prime);
}
return 0;
}