D
doni
Hi,
I am a beginner to C and I wrote a program that takes arguments and
prints it in hex. I am getting a segmentation fault if I dont pass any
arguments instead I want it to display the Usage message that I have.
Here is my simple program.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
char buffer[100];
char ch, * string;
int i, a=0;
if (argc < 1) {
printf("Usage: test <IPv4 Address> \n");
}
else {
string = argv[1];
strcpy(buffer, string);
a = strlen(buffer);
printf("a value is: %d", a);
for (i = 0; i < a; i++)
{
printf("Value is: %02x\n", buffer);
//printf("Value is: %X\n", buffer);
}
}
}
Thanks,
doni
I am a beginner to C and I wrote a program that takes arguments and
prints it in hex. I am getting a segmentation fault if I dont pass any
arguments instead I want it to display the Usage message that I have.
Here is my simple program.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
char buffer[100];
char ch, * string;
int i, a=0;
if (argc < 1) {
printf("Usage: test <IPv4 Address> \n");
}
else {
string = argv[1];
strcpy(buffer, string);
a = strlen(buffer);
printf("a value is: %d", a);
for (i = 0; i < a; i++)
{
printf("Value is: %02x\n", buffer);
//printf("Value is: %X\n", buffer);
}
}
}
Thanks,
doni