-1
分段錯誤:在使用regcomp的行上拋出分段錯誤。 我已經使用gdb來運行程序。Regcomp拋出分段錯誤
我試圖:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <regex.h>
#define LINE_LENGTH 256
main()
{
char *c_char;
char *cp;
char *temp;
regex_t regex;
int reg = 0;
char f_input[] = {"path/path/.pc"};
FILE *input;
input = fopen(f_input, "r");
while (fgets(temp, LINE_LENGTH, input) != NULL)
{
temp = (char*)malloc(sizeof(char)*LINE_LENGTH);
if((cp = strstr(temp, "#define")) != NULL)
{
temp +=7;
memset(c_char, '\0', sizeof(char)*50);
c_char = strtok(temp, " ");
reg = regcomp(®ex, "^[A-Z]", 0);
reg = regexec(®ex, c_char, 0, NULL, 0);
if (reg == REG_NOMATCH)
{
fprintf("%s should be in upper case.", c_char);
}
}
}
}
來到線之後: 「REG = regcomp(&正則表達式, 」^ [A-Z]「,0);」我試圖打印正則表達式值... 「p正則表達式」。 它打印:
"{buffer = 0x0, allocated = 0, used = 0, syntax = 0, fastmap = 0x0.........}"
您的問題提供了近似爲零的信息,並且無法回答。是什麼讓你認爲你提供的代碼與真正的崩潰有什麼關係?什麼是崩潰堆棧跟蹤? –
嗨,我無法粘貼代碼或任何其他屏幕截圖,所以我編輯了上面的代碼。請檢查。 – JustStarted