快速问题,我试图每次从字符数组中的字符不是随后的字符时打印一个新行。例如,如果text [i]是'a'而text [i + 1]不是'b',那么printf(“\ n”);如何直接比较数组中的第一个和第二个元素?
示例I/O将是:
input: "[email protected]"
output: ab
123
XY
输出现在的问题是:
\n
\n
\n
这是当前代码我现在有:
void printNext(const char *t){
//variable declerations
int i;
for(i = 0; t[i] != '\0'; i++){
if(t[i] != t[i + 1])//line in question, which isn't working
printf("\n");
else if(t[i] >= '0' && t[i] <= '9')
printf("%c",t[i]);
else if (t[i] >= 'A' && t[i] <= 'Z')
printf("%c",t[i]);
else if(t[i] >= 'a' && t[i] <= 'z')
printf("%c",t[i]);
}//end for
}//end printNext
主要功能是:
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void printNext(const char *);
int main(void){
const char t[40] = "[email protected]";
printf("the original sequence of strings is: %s\n", text);
printf("new string is: \n");
printNext(t);
}
你居然没问一个问题。如果你的程序不能正常工作,请说明确切的输入,预期输出和实际输出。另外,请提供[mcve]。 – kaylum
如何将if语句更改为if(t [i] + 1!= t [i + 1])? – Shiping
@minigeek实际输出或具体问题在哪里?我们所有的是“不工作”。 – kaylum