65,183
社区成员




#include <iostream>
using namespace std;
const int N = 80;
void delchar(char *p, char x) { //删除字符串p中的字符x,这个函数是对的。
char *p1 = p;
for (; *p!='\0'; p++) {
if (*p != x)
*p1++ = *p;
*p1 = '\0';
}
}
int main () { //主函数中似乎存在一些问题?但是找不到。
char c[N], *pt;
pt = "tiankongdaxue";
pt = c;
delchar (pt,'a');
cout << c << endl;
return 0;
}
#include <iostream>
using namespace std;
const int N = 80;
void delchar(char *p, char x) { //删除字符串p中的字符x,这个函数是对的。
char *p1 = p;
for (; *p!='\0'; p++)
if (*p != x)
*p1++ = *p;
*p1 = '\0';
}
int main () { //第一种方法
char c[N] = "tiankongdaxue";
delchar(c,'a');
cout << c << endl;
}
/*
int main () { //第二种方法
char c[N] = "tiankongdaxue";
char *pt = c;
delchar (pt,'a');
printf("%s",c);
return 0;
}
int main () { //手动输入方法
char c[N];
char *pt = c;
gets(pt);
delchar (pt,'a');
printf("%s",c);
return 0;
}
*/
/* 我的错误
int main () {
char c[N];
char *pt = c; //pt首先指向c
pt = "tiankongdaxue"; //pt这时候已经指向另外一个字符串了
delchar (pt,'a');
printf("%s",c);
return 0;
}*/
#include <iostream>
using namespace std;
const int N = 80;
void delchar(char *p, char x) { //删除字符串p中的字符x,这个函数是对的。
char *p1 = p;
for (; *p!='\0'; p++)
if (*p != x)
*p1++ = *p;
*p1 = '\0';
}
int main () { //这一种自己输入tiankongdaxue的话可以输出结果,而且结果是对的。
char c[N];
char *pt = c;
gets(pt);
delchar (pt,'a');
printf("%s",c);
return 0;
}
int main () { //但是这一种自己定义了,为什么就不能输出结果了呢?
char c[N];
char *pt = c;
pt = "tiankongdaxue";
delchar (pt,'a');
printf("%s",c);
return 0;
}
int main () { //主函数中似乎存在一些问题?但是找不到。
char c[N] = "tiankongdaxue";
delchar (c,'a');
for (int i = 0; i < N; i++)
cout << c[i];
return 0;
}
#include <iostream>
using namespace std;
const int N = 80;
void delchar(char *p, char x) { //删除字符串p中的字符x,这个函数是对的。
char *p1 = p;
for (; *p!='\0'; p++) {
if (*p != x)
*p1++ = *p;
//*p1 = '\0';///////////////
}
}
int main () { //主函数中似乎存在一些问题?但是找不到。
char c[N] = "tiankongdaxue";//////////
delchar (c,'a');
cout << c << endl;
return 0;
}
#include <iostream>
using namespace std;
const int N = 80;
void delchar(char *p, char x) { //删除字符串p中的字符x,这个函数是对的。
char *p1 = p;
for (; *p!='\0'; p++) {
if (*p != x)
*p1++ = *p;
}
*p1 = '\0';
}
int main () { //主函数中似乎存在一些问题?但是找不到。
char c[N] = "tiankongdaxue", *pt;
pt = c;
delchar (pt,'a');
cout << c << endl;
return 0;
}