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

答案是cmue

#include <stdio.h>
#include <string.h>
#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;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-12-25
#include <stdio.h>
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

本回答被提问者和网友采纳
第2个回答  2017-12-25
#include <stdio.h>
#include <string.h>
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;
}
第3个回答  2012-05-18
#include <stdio.h>
#include <string.h>
#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;
}
第4个回答  2012-05-18
#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");
}
相似回答