c语言: 将字符串computer赋给一个字符数组,然后从第一个字母开始间隔地输出该串。请用指针实现

2024-11-03 17:11:46
推荐回答(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
using namespace std;
int main()
{
char* str="computer";
char* p=str;
cout< while(*p!='\0'||*(p-1)!='\0')
{
cout<<*p<<" ";
p=p+2;
}
return 0;
}

回答3:

#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;
}

回答4:

#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");
}

回答5:

#include
#include
{
int i;
char a[81]=''computer'';
char * p=a;
while(*p!='\0')
{
printf("%s",*p);
p++;
}
printf("\n");
}