Hello cboard! I'm both new to the forum, and new to C Programming and am struggling to achieve validation of the start of a string passed through terminal.
Below is both the code and my general thinking slung together:
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *address;
char *addresspre;
//request input
printf("Enter a URL (http://example.com):\n");
//address is passed as argv[1] when run from terminal
printf("Saving address \"%s\".\n", argv[1]);
//copies argv[1] into 'address'
strcpy(address, argv[1]);
addresspre = address;
address = address+7;
strncmp(address, addresspre, strlen(addresspre));
}
Here is what I'd type to run from terminal:
Code:
./httptest http://blah.com
(or something to that effect)
I appreciate it doesn't achieve much but I would like this part of my program to check that 'argv[1]' (as passed through terminal on execution) starts with 'http://'. It's all part of a bigger program I am working on; here I have just taken out what I am struggling with.
Ideally I'd like an if statement to be satisfied with 'http://' being present and continue - with a block of working code I have all ready got - and an else to printf a failure message and return 0 (the latter I can do myself).
Apologies for for slinging in random working parts but I am new to C and have only past experience with Java, a whole different kettle of fish as I'm sure you'll know.
I'd much appreciate any help or direction with getting further forward with this. Thanking you in advance.