guys, i have a problem that i want to read a string called its a hexadecimal string and so contains both chars and ints.
the string is something like :
Code:
RAWSTUFF 000.000 1343442 32523523 DEF457457457457475745HFE 3463436.000
i would want to ignore the words and the 0000.000 but keep everything else. there is other stuff i´d like to ignore but i will figure that out after a kick in the right direction.
p.s. the string is a variable which makes my life harder. however, the stuff i want to ignore remains the same. my attepmts are shown below.
i´d just like to know how to ignore the stuff because i think i can re-arrange myself.
all help appreciated.
my attempts
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/********************************************************
* my_strchr -- Finds a character in a string. *
* Duplicate of a standard library function, *
* put here for illustrative purposes *
* *
* Parameters *
* string_ptr -- String to look through. *
* find -- Character to find. *
* *
* Returns *
* pointer to 1st occurrence of character *
* in string or NULL for error. *
********************************************************/
char *my_strchr(char * string_ptr, char find)
{
while (*string_ptr != find) {
/* Check for end */
if (*string_ptr == ' 0')
return (NULL); /* not found */
++string_ptr;
}
return (string_ptr); /* Found */
}
int main()
{
char line[250]; /* The input line */
char *first_ptr; /* pointer to the writing*/
char *last_ptr; /* pointer to the zeros */
int *second_ptr; // pointer to the 0 value
fgets(line, sizeof(line), stdin);
/* Get rid of trailing newline */
line[strlen(line)-1] = 'RAWSTUFF';
/* Get rid of 0´s */
line[strlen(line)-1] = '000.00000';
last_ptr = line; // writing printed at new line//
first_ptr = my_strchr(line, ' '); // Find Spaces //
second_ptr = my_strchr(line, '0'); // Find 0´s //
/* Check for an error */
if (first_ptr == NULL) {
fprintf(stderr,
"Error: Unable to find space in %s\n", line);
exit (8);
if (second_ptr == NULL) {
fprintf(stderr,
"Error: Unable to find 0 in %c\n", line);
exit (8);
}
*first_ptr = '\0'; // Zero out the slash //
*second_ptr = '00'; // Zero out the Zeros //
++first_ptr; // move along array //
++second_ptr; // move along array //
printf("First:%s Last:%s\n", first_ptr, last_ptr);
return (0);
}