#include <iostream>
#include <cstdio>
using namespace std;
int strleng( char const str[]) { ///only read
int i = 0;
while(str[i] != '\0') {
i++;
}
return i;
}
int main()
{
char str[100];
gets(str);
int res = strleng(str);
cout << res << endl;
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <cstdlib>
using namespace std;
void test() {
char str[5];
strcpy(str, "abcde");
printf("%s\n", str);
}
int main()
{
const char *str = {"abcdef"} ;
char *p;
p = (char *)malloc(sizeof(char)*(strlen(str)+1));///right!
///p = (char *)malloc(sizeof(char)*strlen(str));//wrong! '\0';
strcpy(p, str);
printf("%s\n", p);
test();
return 0;
}
C语言学习
最新推荐文章于 2024-11-27 16:47:44 发布