指针的错误赋值

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值