ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
code is #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
int main ()
{
char *rept_cell[900];
char cell_alarm[5800];
char temp_cell_all[5800];
char cell_alarm1[2000];
FILE *input_file, *output_alarm, *output_clear, *file_2MB;
int M_STAR;
int testptr;
char *teststr;
char *teststr1;
int STAR;
int ECP;
int AP;
int ACK_STAR;
int ACK_ECP;
int ACK_AP;
int file_pointer = 0;
int flag_2mb;
//while (1)
// {
input_file = fopen ("031209.APX", "r");
output_alarm = fopen ("rept_alarms.dat", "w+");
output_clear = fopen ("rept_clear.dat", "w+");
while (!feof (input_file))
{
M_STAR = 0;
STAR = 0;
AP = 0;
ECP = 0;
ACK_STAR = 0;
ACK_ECP = 0;
ACK_AP = 0;
fgets (rept_cell[0], 900, input_file);
printf("hi");
cell_alarm[0] = '\0';if ((strstr (rept_cell[0], "*") != NULL)
&& (strstr (rept_cell[0], "REPT:CELL") != NULL)
&& (strstr (rept_cell[0], "BOGGED") == NULL))
{
strcat (cell_alarm, rept_cell[0]);
cell_alarm[strlen (cell_alarm) - 1] = ';';
while (strstr (rept_cell[0], "/") == NULL)
{
fgets (rept_cell[0], 900, input_file);
if ((strstr(rept_cell[0],
"MEAS ERROR") == NULL) && (strstr (rept_cell[0], "CALLDROP") == NULL)&&
(strstr(rept_cell[0],"DBMISMATCH") == NULL))
STAR = 1;
{
if ((strchr (rept_cell[0], '\n') != NULL) && (strchr(rept_cell[0],'/') == NULL))
{
strcat (cell_alarm,
rept_cell[0]);
cell_alarm[strlen (cell_alarm) - 1] = ' ';
}
else if (strchr (rept_cell[0], '/') != NULL)
{
*rept_cell[0] = ';';
strcat (cell_alarm, rept_cell[0]);
}
}
}
}
if ((M_STAR == 1) || (STAR == 1) || (AP == 1))
fprintf (output_alarm, "%s", cell_alarm);
}
// }
fclose(input_file);
compiler is gcc
to run i use ./a.out
This is wrong because the first argument to fgets should be a char*, not char. I'm a little suprised the compiler didn't warn about that. If not, compile with -Wall.
please post code under [ code ] ... [ /code ] (without the spaces) in the future.
The problem is, you're not allocating space for rept_cell[0]. You have an array of 900 char * pointers and you're only using the first index in the array. I'd either change the definition char *rept_cell[900]; to just char rept_cell[900]; and then go through with Find and Replace to change every instance of rept_cell[0] to rept_cell or allocate memory for rept_cell[0]. I don't really see a need for the array of pointers in the code you pasted though. Best to drop the * from the definition and then Find and Replace like I mentioned. The fact that your fgets() call specifies a buffer size of 900 bytes makes me think that you didn't intend to create an array of pointers in the first place anyway.
EDIT: to aluser, rept_cell[0] is a char * in the code he pasted. That's why gcc allowed it. The problem is that rept_cell[0] just points to garbage.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.