Articles

Metasploit Framework Windows Tutorial
Remote Desktop Connection
Windows Processes That May Be Dangerous
How-To use NetCat a Tutorial
Common Linux Commands
Common Ports
Netcat Commands
HTTP Response Codes
War-Google Hack Terms
Wardriving
Avoiding Social Engineering and Phishing Attacks
Intrusion Detection on Linux
Linux Intrusion Detection
Penetration Testing Guide
Penetration Testing Tools
Social Engineering Fundamentals, Part I: Hacker Tactics
Social engineering (computer security)
The Psychology of Social Engineering

The Archives

General GSO
GovernmentSecurity.org News & Suggestions
In The News
Open Topic
General Security Information
Trash Can
Exploit & Vulnerability Mailing List Archives
Trial Member Forum
Product and Program Reviews GSO Tutorials
System Security
Windows Systems
Beginners Section
Linux & Unix Systems
File Downloads
Exploit Research & Discussion Trojan & Virus Errata
Networking Security / Firewall / IDS / VPN / Routers
System Hardening
E-Mail Security
Wifi Security
Trial Member Uploads
Upload discovered Trojans & Mal ware
GSO Programming Section
C , C++ , VC++
Visual Basic.NET
Perl /CGI
Java/Javascript
PHP/XML/ASP/HTML
Assembly + Other
The Cork Board
Network Security Consultant Directory
Network Security Jobs
The Archives
Encryption Information
General Network Security
Internet Anonymity
HTTP Protocol Security
Linux Security
MS IIS Information
Exploit Articles
Programming / Tool Design
GSO Software Projects
Public Downloads
Microsoft Security Questions and Papers

Full Version: A C Question
Norse
Hi, i am new to C and am still learning but i am trying to make a program that takes any input and turns it in to hex but i am having some problems with it because when i compile it and type in some text it only translates that first letter i am using %h to write my text to the screen so my print statment it like this.
CODE

printf("%h",text);


can some one tell we what might be a better way of doing this.
tibbar
perhaps the char buffer text is a single char and not char[256] say?
gilbert0
first of all: i don't know what %h does or if it even exists, but %x should normally give you hex output.

You must also understand that C doesn't really have a string type, you have to use arrays to store your stuff in.
printf("%s", string); will print out your entire string, but other operands won't do that.
%c, %d, %x will only work for one value.
So how do we solve this problem?
We can make a string and then go through all the values and print them
CODE

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   int i;
char string[] = "aaaaaaaaa";
for(i = 0; i < (strlen(string)); i++) {
     printf("%x ", string[i]);
     }
return 0;

}


However, instead of using fget() to make an array, and then going through all our values one by one, we can also just change them at the input line:

CODE

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   int ch;
   while( (ch = getchar() ) != '\n') {
          printf("%x ", ch);
          }
         
   return 0;
   
}          

this program will take a character at a time from the standard input and then print its hexadecimal value, until a newline is reached.

I hope this answers your question,
if it doesn't or you don't understand some things,

let me know,

gilbert
Norse
Thank you for your replys they helped a lot i under stand it now and i just typed in my code fast, sorry for the %h and not %x.
phizer
Cool little program gilbert0! I had three classes of C++ and never really did anything as cool as this little C program (*cough*, shitty state college). Thanks for sharing the knowledge mate.
gilbert0
I'm glad i could help, and if you really want to learn a lot of C, i recommend the book "Pointers on C" by Kennth A. Reek. It is a bit advanced and gets a bit hard some times, but you can really learn a lot from it.
skiddieleet
QUOTE(phizer @ Jul 17 2005, 12:47 PM)
Cool little program gilbert0!  I had three classes of C++ and never really did anything as cool as this little C program (*cough*, shitty state college).  Thanks for sharing the knowledge mate.
*


phizer, you may want to consider changing schools wink.gif. Although the school probably didn't think that translating strings into hex was very valuable.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.