指针的错误赋值
来源:互联网 发布:蛮牛unity3d 编辑:程序博客网 时间:2024/05/17 23:23
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
FILE * fp;
char *line = NULL;
char *dst = "kernel";
char *word[8192];
int rownum = 0;
int wordid = 0;
int status = 0;
int i, j;
size_t len = 0;
fp = fopen("./cai.txt", "r");
//fp = fopen("/var/log/messages", "r");
for (i = 0; i <= 255; i++)
word[i] = NULL;
if (fp == NULL) {
printf("打开文件\"/var/log/messages\"不存在或无权访问!\n");
return 1;
}
while (getline(&line, &len, fp) != -1) {
rownum++;
wordid++;
if(strstr(line, dst) != NULL) {
for (j = 0; j <= wordid; j++) {
if (line == word[j]) {
status++;
}
}
if (status == 0) {
word[wordid] = line; //此处两个值都是指针 如果这么赋值的话 word[wordid]和line是同一个指针,如果将a指针的值付给b指针应该是*a=*b这样
printf("3#This line is new:%d \t %s", rownum, line);
}
status = 0;
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
FILE * fp;
char *line = NULL;
char *dst = "kernel";
char *word[8192];
int rownum = 0;
int wordid = 0;
int status = 0;
int i, j;
size_t len = 0;
fp = fopen("./cai.txt", "r");
//fp = fopen("/var/log/messages", "r");
for (i = 0; i <= 255; i++)
word[i] = NULL;
if (fp == NULL) {
printf("打开文件\"/var/log/messages\"不存在或无权访问!\n");
return 1;
}
while (getline(&line, &len, fp) != -1) {
rownum++;
wordid++;
if(strstr(line, dst) != NULL) {
for (j = 0; j <= wordid; j++) {
if (line == word[j]) {
status++;
}
}
if (status == 0) {
word[wordid] = line; //此处两个值都是指针 如果这么赋值的话 word[wordid]和line是同一个指针,如果将a指针的值付给b指针应该是*a=*b这样
printf("3#This line is new:%d \t %s", rownum, line);
}
status = 0;
}
}
return 0;
}
- 指针的错误赋值
- 指针赋值容易犯的一个错误
- 低级错误,野指针赋值
- 二位数组与二级指针的错误赋值
- 指针的赋值问题
- 指针的赋值
- 指针赋值的问题
- 指针赋值的问题
- 3. 指针的赋值
- 指针赋值的问题
- 指针的赋值运算
- 指针变量的赋值
- C指针错误(3)-链表的尾指针要赋值NULL
- 指针的赋值与引用的赋值
- __attribute__((packed)) 指针传递,赋值错误问题
- 经典的指针错误,在方法中,指针不要相互赋值,应该赋这个指针的内容。
- 小心指针间的赋值
- 指针赋值时的相容性
- MPEG-2视频编码技术漫谈
- 前还算是个新鲜事物
- H264基本概念--【转】图像、帧、片、NALU
- Vim史上最全面的知识点总结
- NAND write: '$filesize' is not a number
- 指针的错误赋值
- UVAlive 2911 Maximum(贪心)
- 【菜鸟学习Linux】-第二章- Linux环境搭建-使用VMware9联网设置”
- Eclipse cdt安装与使用 (C/C++插件安装)
- HDU4697 Convex hull
- 查找首个非重复字符
- HDU 4704 Sum 费马小定理+快速幂
- Spring中使用getSession()与通过HibernateTemplate进行数据操作的差别
- Hibernate默认连接池使用问题