69,373
社区成员
发帖
与我相关
我的任务
分享
#inculde <stdio.h>
#inculde <string.h>
int main(void)
{
int i;
int status;
int nbytes = 20;
int equal = 0;
/*Initialize instructions empty string*/
for(i=0;i<100;i++)
instructions[i] = "";
/*Prompt user to input instructions*/
i = 0;
while( i<100)
{
printf("%s","Please input next instruction:\n");
fflush(stdout);
instructions[i] = (char *) malloc (nbytes + 1);
status = getline (&instructions[i], &nbytes, stdin);
if (status == -1)
{
puts ("ERROR!");
}
else
{
puts ("You typed:");
puts (instructions[i]);
}
equal = strcmp("HALT",instructions[i]);
printf("Value in instructions is: %s\n",instructions[i]);
printf("Equal's value is: %d\n",equal);
i++;
}
}
#include <stdio.h>
#include <string.h>
int main(void)
{
char *s = "HELLO";
printf("%d\n",strcmp("HELLO",s));
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NBYTES 20
#define NBYTE_Number 5
int main(void)
{
int i;
int status=1;//便于在C环境中程序的运行,始终保持为有效状态
char *instructions[NBYTES];
int equal = 0;
i = 0;
printf("Please input the first instruction:\n");
while(i<NBYTE_Number)
{
fflush(stdout);
instructions[i] = (char *) malloc (NBYTES + 1);
memset(instructions[i], 0x00, NBYTES + 1);
if (status == -1)
{
puts ("ERROR!");
}
else
{
puts ("You typed:");
if(i!=0)
printf("Please input next instruction:\n");
gets (instructions[i]);
}
equal = strcmp("HALT",instructions[i]);
printf("Value in instructions is: %s\n",instructions[i]);
free(instructions[i]);
printf("Equal's value is: %d\n",equal);
i++;
}
return 0;
}