Thread: error compiling a little program

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    18

    error compiling a little program

    hi

    im trying to make a program in linux to call another program doing first a check to see if the HD has the right serial number

    i know if i put the serial in some parts of the code is possible to edit the value with a hex editor after compile, so i was thinking about to put the serial on a #define, but isnt working:


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TRAVA XXXXXXXXXX2568
    
            int hd ()
            {
            	system("ls /dev/disk/by-id/ |cut -d_ -f3 |head -n 1");
            }
    
     int main ()    
    {
    
    	if (hd() == TRAVA)
    		system("./game");
    	else {
    		printf("Erro");
    	}
    }
    comand to compile:

    Code:
    gcc abrir.c -o abrir
    the result:

    Code:
    abrir.c:14: error: ‘XXXXXXXXXX2568’ undeclared (first use in this function)
    abrir.c:14: error: (Each undeclared identifier is reported only once
    abrir.c:14: error: for each function it appears in.)

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    When you #define TRAVA, is TRAVA a string of digits or is it a number?

    print it out as both a string, and as a number, and tell us which it is.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    18
    when i execute in terminal the comand

    Code:
    ls /dev/disk/by-id/ |cut -d_ -f3 |head -n 1
    i have this result with this hard disk:

    Code:
    S19GJ50Q342568
    so, i think i need to put this in #define line to work on this hd:

    Code:
    #define TRAVA S19GJ50Q342568
    to work like:

    Code:
    " if {ls /dev/disk/by-id/ |cut -d_ -f3 |head -n 1 == S19GJ50Q342568} ok"
    Last edited by fbs777; 03-17-2009 at 09:20 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I believe that string of char's should be put into a char array[], and then have an end of string null added onto the end of it. (Leave at least one char for that in your array)

    Then you can compare it to any other string with

    if(strcmp(arrayname1, arrayname2) == 0)
    //it's a match.

    In C you can't compare a string to another string, by using the simple:
    if(string1 == string2)

    Doesn't work.

  5. #5
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Additionally, you could store the serial number in /etc/ or someplace else, and read that in, rather than hand-modifying the ELF executable.

    See the man pages for fopen, fgets, and fputs for more info on that.

    And, I'm sure there's an entry somewhere in the FAQ at this website.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM