fal*_*n21 -3 c pointers function
我正在努力解决这个问题.基本上,这个function void check(char *tel, char *c)数组的第一个值必须是数字2,而其他数字必须是数字之间的数字0 and 9.如果满足条件,将打印V,否则将打印F.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
void check(char *tel, char *c){
int i;
if(*tel!=2) printf("Error\n");
*c='F';
return; //I guess this return is wrong
if(*tel==2)
for(i=0;tel[i]<9;i++){
if(isdigit(tel[i]));
else{
printf("Error!\n");
*c='F';
break;
return;} //this one might be in bad use too
}
else
*c='V'; //having troubles here.. i'm not seeing a way to fix this
}
int main(){
char number[9]={2,3,4,5,6,7,4,5,3};
char car;
check(number,&car);
printf("%c \n", car);
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
你错过了各地的许多你的花括号if和else块.正确缩进和格式化代码将有很长的路要走.
if(*tel!=2) printf("Error\n"); *c='F'; return;
Run Code Online (Sandbox Code Playgroud)
例如,以上应该是:
if (*tel != 2) {
printf("Error\n");
*c = 'F';
return;
}
Run Code Online (Sandbox Code Playgroud)
请,请:正确缩进您的代码.
编辑:为了更明确,这是您的代码重新格式化后的样子.你现在看到错误,你错过花括号的地方?
提示:我已经标记了应该带有/*******/注释的行.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void check (char *tel, char *c) {
int i;
if (*tel != 2) /*******/
printf("Error\n");
*c = 'F';
return;
if (*tel == 2) /*******/
for (i = 0; tel[i] < 9; i++) {
if (isdigit(tel[i])) /*******/
;
else {
printf("Error!\n");
*c = 'F';
break;
return;
}
}
else /*******/
*c = 'V';
}
int main() {
char number[9] = {2, 3, 4, 5, 6, 7, 4, 5, 3};
char car;
check(number, &car);
printf("%c \n", car);
system("pause");
}
Run Code Online (Sandbox Code Playgroud)