Jump to content

On the subject of making a troubleshooter


McJobless
 Share

Recommended Posts

Very specific (I hope), for C Programming, I need a way of scaning codes in file and reporting if they are broken or not. Any suggestions?

Link to comment
Share on other sites

well one way you could do it is you could compare a line from one file too a line from another file that works. so you have a sort of database file for all the right ways and one of all the wrong ways. i could probably come up with the base code for you if you'd like. is it going to be in C or C++?

Link to comment
Share on other sites

well one way you could do it is you could compare a line from one file too a line from another file that works. so you have a sort of database file for all the right ways and one of all the wrong ways. i could probably come up with the base code for you if you'd like. is it going to be in C or C++?

I'm using C, but I'll I really need to too know the code for comparing strings...otherwise, I have a general idea on how to make this work.

Link to comment
Share on other sites

Havinh trouble. Here is the source so far:


#include <stdio.h>

#include <string.h>

#include <stdlib.h>


     int readfile(void);

     int test1 (void);


     char filepath[255];

     void abort (void);

     int crashfileread;

     char legocode[7] = {'L', 'e', 'g', 'o', '*', ' ', '{',};

     char clegocode[8] = {'L', 'e', 'g', 'o', '*', ' ', '{',};

     int t = 1;


int main()

{  


     printf ("\n------------------------------------------\n");     

     printf ("Welcome To the Debugger.\n\n");

     printf ("In this application you'll be able to check Lego.cfg for any errors.\n\n");

     printf ("Currently, this program is at:\n");

     printf ("Version 0.01B: Testers Edition\n\n");

     printf ("Developer: Extreme110\n");

     printf ("Official Test-Team: Extreme110, \"YOUR NAME HERE\"\n");

     printf ("\n------------------------------------------\n");

     printf ("To start, please type in the directory of the file:\n");

     scanf ("%s",filepath);

     printf ("Ok, gimme a second...\n");

     readfile ();

     if (crashfileread = 1) {

        abort;

        }

}


int readfile()


{

     FILE *pFile;

     pFile = fopen (filepath,"r");

     if (!pFile) {

        printf ("Can't Find The File Specified\n");

        fclose (pFile);

        crashfileread = 1;

        return 1;

        }

     else {

          printf ("File Found. Scan will begin...\n");

          fclose (pFile);

          test1 (); 

          }

}   


int test1()


{


     FILE *pFile;

     pFile = fopen (filepath,"r"); 

     fgets(filepath,8,stdin);

     if (strcmp(legocode,clegocode) != 0){   

        printf ("Function \"Lego* {\" is decleared. Continuing Search...\n");

     }else{

        printf ("The line \"Lego* {\" is missing from the first part of your .cfg.\nPlease fix this.\nContinuing search...\n");

     }

     return 0;

}

I'm having the problem at test1, when we get to the if statement. When I run the program with a code that doesn't have "Lego* {" in it, it still says that it has. Problem: The debugger then won't do its job because if someone has ommited that line out then that's a problem with the code the debugger should be pointing out.

It seems however if the compilier is ignoring ALL my "if" statements.

If anyone has a fix, it would be much appreciated.

Link to comment
Share on other sites

well C++ is more my area but i did have a look at the code. i ran this with the Lego.cfg file and it didn't find "Lego* {".

does this only check the first line?

I'm having the problem at test1, when we get to the if statement. When I run the program with a code that doesn't have "Lego* {" in it, it still says that it has. Problem: The debugger then won't do its job because if someone has ommited that line out then that's a problem with the code the debugger should be pointing out.

well i'm having the opposite problem. i made a .txt file, put "Lego* {" in it, ran the program and and it didn't find it.

Link to comment
Share on other sites

well C++ is more my area but i did have a look at the code. i ran this with the Lego.cfg file and it didn't find "Lego* {".

does this only check the first line?

I'm having the problem at test1, when we get to the if statement. When I run the program with a code that doesn't have "Lego* {" in it, it still says that it has. Problem: The debugger then won't do its job because if someone has ommited that line out then that's a problem with the code the debugger should be pointing out.

well i'm having the opposite problem. i made a .txt file, put "Lego* {" in it, ran the program and and it didn't find it.

I fixed it. Turns out that "clegocode" wasn't linked to anything, but was an array holding the same contents as the array it was trying to compare.

Link to comment
Share on other sites

ok glad to see you fixed it. :) if you don't mind me asking why did you choose to make it in C instead of C++?

Link to comment
Share on other sites

ok glad to see you fixed it. :) if you don't mind me asking why did you choose to make it in C instead of C++?

1) I'm still learning C++, yet I have a "good" knowledge of C

2) Dev-C++ won't let me use the iostream.h for C++, so I need to update it, but I'm currently capped so I have to wait till the 19th of the month

3) I thought C could do it, BUT IT LIED!!!

Link to comment
Share on other sites

ahh... ok best to stick with what you know best. :)

Actually, scratch the top message, because I think I found a .h file specially designed to read .cfg files!

Link: http://www.hyperrealm.com/libconfig/

So, yeah, maybe C is a good choice...

nice find. :)

Link to comment
Share on other sites

Anonymouse

ok glad to see you fixed it. :) if you don't mind me asking why did you choose to make it in C instead of C++?

1) I'm still learning C++, yet I have a "good" knowledge of C

2) Dev-C++ won't let me use the iostream.h for C++, so I need to update it, but I'm currently capped so I have to wait till the 19th of the month

3) I thought C could do it, BUT IT LIED!!!

1. You can compile C code in a C++ compiler, they're that similar (C code is almost completely reverse-compatible with C++)

2. It's iostream not iostream.h

Actually, scratch the top message, because I think I found a .h file specially designed to read .cfg files!

Link: http://www.hyperrealm.com/libconfig/

So, yeah, maybe C is a good choice...

You can use that library in C++ too, naturally.

And about that library, it uses a different CFG format. It's not suitable, sorry to disappoint.

Link to comment
Share on other sites

Actually, scratch the top message, because I think I found a .h file specially designed to read .cfg files!

Link: http://www.hyperrealm.com/libconfig/

So, yeah, maybe C is a good choice...

You can use that library in C++ too, naturally.

And about that library, it uses a different CFG format. It's not suitable, sorry to disappoint.

I was a afraid of that after I read several times more. Maybe though I might be able to, how you say, "customise" it a little...?

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.