用c语言编写一个程序,将字符串computer赋给一个数组然后从第一个字母开始间隔输出。用指针完成

答案是cmue
2024-11-25 14:13:13
推荐回答(5个)
回答1:

#include
#include
#define MAX_LENGTH 32

int main()
{

char str[MAX_LENGTH] = {0};
char *pStr = (char*)&str;

//1. 将字符串computer赋给一个字符数组
strcpy(str, "computer");

//2. 然后从第一个字母开始间隔地输出该串
while(*pStr != '\0' )
{
printf("%c\n", *pStr);
pStr++;
}

return 1;
}

回答2:

#include 
int main()
{
char str[]="computer";
char *p;
for(p=str;*p!='\0';p+=2)
printf("%c",*p);
printf("\n");
}

//运行结果
F:\c_work>a.exe
cmue

回答3:

#include
#include
void IntervalStr(char *pStr, int nLen)
{
for(int i = 0; i < nLen; i+=2)
{
printf("%c", pStr[i]);
}
}
int main(int argc, char argv[])
{
char acBuf[16] = "computer";
IntervalStr(acBuf, strlen(acBuf));
return 0;
}

回答4:

#include
#include
#define N 100

int main()
{

char a[N] = {0};
char *p= a;
strcpy(p, "computer");
while(*p!= '\0' )
{
printf("%c ", *p);
p++;
}
printf("\n");
return 0;
}

回答5:

#include "stdio.h"
void main()
{
char a[100];
char* computer="my string";
strcpy(a,computer);
int i=0;
while(*a!="\0")
printf("%c ", *a++);
printf("\n");
}