Like Tree3Likes
  • 1 Post By Salem
  • 1 Post By Salem
  • 1 Post By jamesvdb

Rusty old programmer seeks help for small modification

This is a discussion on Rusty old programmer seeks help for small modification within the Projects and Job Recruitment forums, part of the Community Boards category; Hi, I have an old command line tool written in C. It's a very fast tool that searches for patterns ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    4

    Rusty old programmer seeks help for small modification

    Hi,

    I have an old command line tool written in C. It's a very fast tool that searches for patterns in a binary file (can replace it too) and outputs all the offsets where it finds the pattern. An 400Mb file is searched in less than 1 second !
    But the problem is that the offset values that this utility ouputs are in hexadecimal format. It would be easier if it was in decimal format.

    I have the c code. Is there any passionated c-programmer out there that would help me out with this one ? As I'm programming for more than 25 years in another language, I do not remember enough for the C language (which is a great language for lighting-speed programs !

    You can email me at jamesvdb@lavabit.com
    I can send you the source code and also the binary version (exe).

    I hope someone can help me out !

    Greetings from Belgium (yep, that small European country)

    James

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    960
    I'd be interested to see what computer you're running that can read 400 MB in one second

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    4
    I have a HP probook 4710s
    The testfile is exactly 385.767.424 bytes
    You are right, it took about 4 seconds. When I re-execute the prog, it's only 1 sec since the testfile is cached. Still, 4 seconds is very fast .... It takes 14 sec for a 1Gb file.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have a variable, that is being printed in hexadecimal. If you want to know what it is in decimal format, just change the printf() format from hexadecimal %x to %d - decimal format.

    That's all there is to it.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You could also just pipe it thru this:
    Code:
    #include <stdio.h>
    
    int main(void) {
    	int x;
    	while (scanf("%x", &x)) {
    		printf("%d\n", x);
    	}
    
    	return 0;
    }
    Altho that presumes the program outputs like this:

    Code:
    ae9b
    13f11
    4461d
    Which it probably is more verbose than that, but if you post exactly what the output looks like, I can tweak it for you tomorrow. This should not affect the runtime of the main program.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > while (scanf("%x", &x))
    Ugh - EOF is also "true" as well.
    MK27 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2012
    Posts
    4
    I know it's easy, but there are 2 problems:

    - it is 25 years since I last used C, I can't read code anymore to find locate the line of code that I need to change
    - I do not have a C compiler, also do not know anymore how to use one

    I hoped someone could quickly change the code and recompile it 4 me ...

    Quote Originally Posted by Adak View Post
    You have a variable, that is being printed in hexadecimal. If you want to know what it is in decimal format, just change the printf() format from hexadecimal %x to %d - decimal format.

    That's all there is to it.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Salem View Post
    > while (scanf("%x", &x))
    Ugh - EOF is also "true" as well.
    Whoops. I'm sure that would have shown up in testing
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > I hoped someone could quickly change the code and recompile it 4 me ...
    In much less than a day, you could have downloaded and installed one of many C compilers, made the small change (as outlined), compiled and tested the code.

    With the added bonus that you would know that the executable was really for the program you have, and not some "joke" (or worse, malicious) program created by some anonymous person you've got no real basis to trust at all.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Jan 2012
    Posts
    4
    Quote Originally Posted by Salem View Post
    > I hoped someone could quickly change the code and recompile it 4 me ...
    In much less than a day, you could have downloaded and installed one of many C compilers, made the small change (as outlined), compiled and tested the code.

    With the added bonus that you would know that the executable was really for the program you have, and not some "joke" (or worse, malicious) program created by some anonymous person you've got no real basis to trust at all.
    Although I do know understand the C language (i'm a clipper programmer) i managed to find it myself (had to change in a print command the parameter %lx into %lu and the output of the program changed from hex to dec as i wanted.

    I even managed to recompile it with Turbo C 2.0 and Digital MArs C++ (new name for Zortech C++). The exe created with Digital Mars was MUCH faster than the exe generated with Turbo C. The exe searches a pattern in a 1 Gb file in 14 seconds !!! (not cached, if I re-execute the program (the 1gb file is cached), then it takes even just 2.9 seconds

    Thanks for the tips everyone, but as allways, if you want something done good and fast, you have to do it yourself

    I wanted to erase this post since it is no longer necessary, but i think it can not be deleted, so this post will remain here for my children, my grandchildren, etc etc (unless on december 21, 2012 the world is ending :d)
    MK27 likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Team Chivalry seeks experienced programmer
    By Sir Alexander in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-13-2010, 10:46 AM
  2. Replies: 1
    Last Post: 01-19-2006, 01:37 PM
  3. small hashing modification
    By jodders in forum C++ Programming
    Replies: 0
    Last Post: 02-09-2005, 11:47 AM
  4. A bit rusty.
    By VegasSte in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-20-2004, 08:11 PM
  5. I'm rusty and I need help
    By phay in forum C++ Programming
    Replies: 6
    Last Post: 08-12-2003, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21