#include <stdio.h>
#include <string.h>
/* 函数声明 */
void func1(void);
static int count=10; /* 全局变量 - static 是默认的 */
int main()
{
char *p="zhang";
char *q;
p=&p[1];
printf("%s,%c,%c\n",p,*p,*(p+2));
memcpy(q,p+1,3);
printf("%s\n",q);
//指针+数组+scanfd76
char str[60]={0x31,0x32,0x33,0x34,0x35,0x36}, *sp=str;//将数组的首地址str赋给指针变量sp
//scanf("%s",sp);
//sp++;
sp=&str[3];
printf("%s,%c,%c\n",sp,*sp,*(sp+2));//pointer,p,n
printf("%s,%c,%c\n",str,str[0],str[3]);//pointer,p,n
while (count--) {
func1();
}
return 0;
}
void func1(void)
{
/* 'thingy' 是 'func1' 的局部变量 - 只初始化一次
* 每次调用函数 'func1' 'thingy' 值不会被重置。
*/
static int thingy=5;
thingy++;
printf(" thingy 为 %d , count 为 %d\n", thingy, count);
}
错误记录:
char ang_buf[] = {0x31,0x32};
char head_buf[] ={0x34,0x31};
char *str = NULL;
#if 0
/****这里用法典型错误:ang一个字节时打印出大长度为3如下,改到2个字节后计算长度正常****/
char ang[]={0x39};
crc_len = strlen( ang);
printf("crcout len 9in =%d\n", crc_len);
/****这以内这样正常:ang一个字符时打印出大长度为1如下****/
char ang[]="9";
crc_len = strlen( ang);
printf("crcout len 9in =%d\n", crc_len);
#endif
#include <stdio.h>
#include <string.h>
int main() {
char zf_send_at_path[100] = "/path/to/your/file.txt"; // 假设这是你的路径
char *filepath;
// 直接将 zf_send_at_path 的地址赋给 filepath
filepath = zf_send_at_path;
// 现在 filepath 指向 zf_send_at_path 中的数据
printf("The file path is: %s\n", filepath);
// 注意:如果你之后修改了 zf_send_at_path 的内容,filepath 指向的内容也会改变
// 因为 filepath 只是指向了 zf_send_at_path 的内存地址
// 例如:
strcpy(zf_send_at_path, "/another/path/to/file.txt");
printf("After modification, the file path is: %s\n", filepath);
return 0;
}
#include <stdio.h>
int main() {
char zf_send_at_path[100] = "/path/to/your/file.txt"; // 初始化数组
char *filepath; // 声明一个字符指针
// 将数组首元素的地址赋给字符指针
filepath = zf_send_at_path;
// 现在filepath指向zf_send_at_path数组的内容
printf("通过filepath访问到的路径是: %s\n", filepath);
// 你可以通过filepath来访问和修改zf_send_at_path的内容(但要注意不要越界)
// 例如,打印第一个字符
printf("第一个字符是: %c\n", *filepath);
// 修改第一个字符(例如改为'T')
*filepath = 'T';
// 打印修改后的数组内容
printf("修改后,通过zf_send_at_path访问到的路径是: %s\n", zf_send_at_path);
return 0;
}