473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to sscanf return integer only

I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;

It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


May 5 '06 #1
17 3436
On 2006-05-05, Yogi_Bear_79 <no****@spamsux.com> wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;

It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


But there _is_ an integer - 7. there's then stuff after the integer.

and what's "|| n_ptr <=0" supposed to do?
May 5 '06 #2
But there _is_ an integer - 7. there's then stuff after the integer.
It needs to fail if there are any characters other than integers or white
space

and what's "|| n_ptr <=0" supposed to do?


Not needed, removed, same results
May 5 '06 #3
On Thu, 4 May 2006 20:23:56 -0400, "Yogi_Bear_79" <no****@spamsux.com>
wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;
The third argument needs an & but I assume that is a typo.

If you want to know whether the data at line is a "well formed"
integer, use strtol which will tell you where it stopped extracting
data. Then examine that char for white space or '\0'.

It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


Remove del for email
May 5 '06 #4
Yogi_Bear_79 wrote:
But there _is_ an integer - 7. there's then stuff after the integer.


It needs to fail if there are any characters other than integers or white
space

and what's "|| n_ptr <=0" supposed to do?


Not needed, removed, same results


sscanf isn't the best tool for the job for a couple of reasons, not the
least of which is that trying to convert a number of too large a
magnitude results in undefined behavior.

The following program will read a line at a time from stdin and attempt
to convert it to an integer using the strtol function. If the line
contains any invalid characters, an error message is displayed and the
offending character is pointed out. If a range error occurs (the
number was too large/small to store in a long int), an appropriate
message is diaplayed. This version uses 'long int' and accepts
negative numbers, remove the minus sign from the string of allowed
characters if you just want to accept positive numbers. The code is a
little verbose since it implements error checking.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "-0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtol(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %ld\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}

The strspn function returns the number of characters in the input
string that are in the "allow" string, this must be the same as the
length of the string itself if all the characters are valid, otherwise
we print an error message displaying the location of the offending
character and continue.

The strtol function will skip leading whitespace and attempt to convert
the numeric part of the string to a long int. If an underflow or
overflow occurs then strtol returns LONG_MIN or LONG_MAX respectively
and sets errno to ERANGE. We just check errno and print an error if
appropriate, you could compare l to LONG_MIN or LONG_MAX to determine
the type of range error if desired.

If everything goes well, the converted number is displayed.

A couple of notes:

If the input consists of multiple numbers seperated by whitespace, only
the first one will be converted, you didn't specify what should happen
in this case.

If the input contains only of whitespace or the minus sign the
converted value will be 0.

Entering more than BUF_MAX characters at a time may cause unintended
(but not undefined) behavior.

If an invalid input line contains a tab character before the invalid
character, the error message may not correctly point to the invalid
character.

Addressing these caveats is left as an exercise to the reader.

Robert Gamble

May 5 '06 #5
Barry Schwarz wrote:
On Thu, 4 May 2006 20:23:56 -0400, "Yogi_Bear_79" <no****@spamsux.com>
wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;


The third argument needs an & but I assume that is a typo.


<snip>

From its name, I would guess that n_ptr is set to point to an int and is
defined as

int * n_ptr;
--
==============
Not a pedant
==============
May 5 '06 #6

"Barry Schwarz" <sc******@doezl.net> wrote in message
news:ar********************************@4ax.com...
On Thu, 4 May 2006 20:23:56 -0400, "Yogi_Bear_79" <no****@spamsux.com>
wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;


The third argument needs an & but I assume that is a typo.

If you want to know whether the data at line is a "well formed"
integer, use strtol which will tell you where it stopped extracting
data. Then examine that char for white space or '\0'.

It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


I think I understand now. The code as written is reading the line up until
it encounters a non-integer. So 7 & 7H8 both return the same results. And
from yor sufggestion above it will stop extracting at the H which I can use
strtol to examine, and if it stops on anything other than white spaces I
have my error?

Remove del for email

May 5 '06 #7
On Fri, 5 May 2006 09:15:57 +0100, "pemo" <us***********@gmail.com>
wrote:
Barry Schwarz wrote:
On Thu, 4 May 2006 20:23:56 -0400, "Yogi_Bear_79" <no****@spamsux.com>
wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;


The third argument needs an & but I assume that is a typo.


<snip>

From its name, I would guess that n_ptr is set to point to an int and is
defined as

int * n_ptr;


How often do you compare a pointer to less than or equal to zero? If
he had coded *n_ptr <= 0 I would agree with you. Let's agree the code
as written is confusing.
Remove del for email
May 5 '06 #8
Groovy hepcat Yogi_Bear_79 was jivin' on Thu, 4 May 2006 20:23:56
-0400 in comp.lang.c.
How to sscanf return integer only's a cool scene! Dig it!
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;
Presumably n_ptr is a pointer. If not, then not only is it
misleadingly named, but it is also causing undefined behaviour since
sscanf() wants a pointer there. And if n_ptr is a pointer, then the
comparison n_ptr <= 0 makes little or no sense. Perhaps you meant
*n_ptr <= 0?
Also, this line reads in a number (assuming all is correct) and
checks for an error, but takes no action if an error has been
determined to have occurred. Rather pointless, isn't it?
It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


If you must use sscanf() for this, try it this way:

char dummy;
....
if(sscanf(line, "%d%c", n_ptr, dummy) != 1)
{
/* Non-numerical input detected. Handle this error somehow. */
}

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
May 7 '06 #9

"Robert Gamble" <rg*******@gmail.com
Yogi_Bear_79 wrote:
> But there _is_ an integer - 7. there's then stuff after the integer.


It needs to fail if there are any characters other than integers or white
space

> and what's "|| n_ptr <=0" supposed to do?


Not needed, removed, same results


sscanf isn't the best tool for the job for a couple of reasons, not the
least of which is that trying to convert a number of too large a
magnitude results in undefined behavior.

The following program will read a line at a time from stdin and attempt
to convert it to an integer using the strtol function. If the line
contains any invalid characters, an error message is displayed and the
offending character is pointed out. If a range error occurs (the
number was too large/small to store in a long int), an appropriate
message is diaplayed. This version uses 'long int' and accepts
negative numbers, remove the minus sign from the string of allowed
characters if you just want to accept positive numbers. The code is a
little verbose since it implements error checking.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "-0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtol(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %ld\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}

The strspn function returns the number of characters in the input
string that are in the "allow" string, this must be the same as the
length of the string itself if all the characters are valid, otherwise
we print an error message displaying the location of the offending
character and continue.

The strtol function will skip leading whitespace and attempt to convert
the numeric part of the string to a long int. If an underflow or
overflow occurs then strtol returns LONG_MIN or LONG_MAX respectively
and sets errno to ERANGE. We just check errno and print an error if
appropriate, you could compare l to LONG_MIN or LONG_MAX to determine
the type of range error if desired.

If everything goes well, the converted number is displayed.

A couple of notes:

If the input consists of multiple numbers seperated by whitespace, only
the first one will be converted, you didn't specify what should happen
in this case.

If the input contains only of whitespace or the minus sign the
converted value will be 0.

Entering more than BUF_MAX characters at a time may cause unintended
(but not undefined) behavior.

If an invalid input line contains a tab character before the invalid
character, the error message may not correctly point to the invalid
character.

Addressing these caveats is left as an exercise to the reader.

Robert Gamble


I am unable to discern the OP's intent. [snipped from OP:]
sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;
would have wanted to come back with a bunch of concatenated digits. What
if, instead, you wanted a robust means of coming back with an unsigned long?
Elsethread, you hinted that strtol might not be a bad idea.
long strtol(const char *s, char **endp, int base)
The arguments look quite cryptic to me. Joe
May 7 '06 #10
Joe Smith wrote:
"Robert Gamble" <rg*******@gmail.com
Yogi_Bear_79 wrote:
> But there _is_ an integer - 7. there's then stuff after the integer.

It needs to fail if there are any characters other than integers or white
space
> and what's "|| n_ptr <=0" supposed to do?

Not needed, removed, same results
sscanf isn't the best tool for the job for a couple of reasons, not the
least of which is that trying to convert a number of too large a
magnitude results in undefined behavior.

The following program will read a line at a time from stdin and attempt
to convert it to an integer using the strtol function. If the line
contains any invalid characters, an error message is displayed and the
offending character is pointed out. If a range error occurs (the
number was too large/small to store in a long int), an appropriate
message is diaplayed. This version uses 'long int' and accepts
negative numbers, remove the minus sign from the string of allowed
characters if you just want to accept positive numbers. The code is a
little verbose since it implements error checking.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "-0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtol(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %ld\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}

The strspn function returns the number of characters in the input
string that are in the "allow" string, this must be the same as the
length of the string itself if all the characters are valid, otherwise
we print an error message displaying the location of the offending
character and continue.

The strtol function will skip leading whitespace and attempt to convert
the numeric part of the string to a long int. If an underflow or
overflow occurs then strtol returns LONG_MIN or LONG_MAX respectively
and sets errno to ERANGE. We just check errno and print an error if
appropriate, you could compare l to LONG_MIN or LONG_MAX to determine
the type of range error if desired.

If everything goes well, the converted number is displayed.

A couple of notes:

If the input consists of multiple numbers seperated by whitespace, only
the first one will be converted, you didn't specify what should happen
in this case.

If the input contains only of whitespace or the minus sign the
converted value will be 0.

Entering more than BUF_MAX characters at a time may cause unintended
(but not undefined) behavior.

If an invalid input line contains a tab character before the invalid
character, the error message may not correctly point to the invalid
character.

Addressing these caveats is left as an exercise to the reader.

Robert Gamble


I am unable to discern the OP's intent. [snipped from OP:]
sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;
would have wanted to come back with a bunch of concatenated digits.


In a followup the OP indicated that the "|| n_ptr <=0" was extraneous,
I haven't bothered to attempt to discern what its intended purpose
might have been but it doesn't seem to be relevant.
What
if, instead, you wanted a robust means of coming back with an unsigned long?
I am not sure what you mean here, can you clarify?
If you mean modifying my example for unsigned long, just change the
type of l from long to unsigned long, remove the "-" from the list of
allowable characters, and replace the strtol with strtoul.
Elsethread, you hinted that strtol might not be a bad idea.
What do you mean by "elsethread"? I take that to mean elsewhere in
this thread but the only message I have posted in this thread, besides
this one, is the one you are responding to.
long strtol(const char *s, char **endp, int base)
The arguments look quite cryptic to me.


Well, the prototype isn't meant to provide a detailed understanding of
how the function works, especially to someone who has never before
encountered it. The usage of the function is actually very
straightforward, check out your online documentation (man page, etc.),
pick up a good C book, or download n1124 for details.

Robert Gamble

May 7 '06 #11

"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Joe Smith wrote:
"Robert Gamble" <rg*******@gmail.com
[Mr. Gamble's source and comments for a slightly different question
snipped]
> If everything goes well, the converted number is displayed.
What
if, instead, you wanted a robust means of coming back with an unsigned
long?

[modified source:]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
unsigned long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtoul(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %lu\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}
/* end source */
Well, the prototype isn't meant to provide a detailed understanding of
how the function works, especially to someone who has never before
encountered it. The usage of the function is actually very
straightforward, check out your online documentation (man page, etc.),
pick up a good C book, or download n1124 for details.

This compiles and seems to behave. The caveats he mentions for when this
situation would fail seem to have as a precondition that the person on the
keyboard had no business touching a computer. The man pages confused me.
Seemed to be all about Linux. I'm always trolling for a good C book. N
1124 sounds like a party. A little too far away for my vacation
preferences. Thanks for the source. Joe
May 8 '06 #12
Joe Smith wrote:
I'm always trolling for a good C book. N
1124 sounds like a party. A little too far away for my vacation
preferences. Thanks for the source. Joe


Check out "C Programming: A Modern Approach" by K. N. King and "C: A
Reference Manual (5th edition)" by Harbison & Steele. These are two of
the best, most comprehensive books out there.

Robert Gamble

May 9 '06 #13

"Robert Gamble"
Joe Smith wrote:
I'm always trolling for a good C book. N
1124 sounds like a party. A little too far away for my vacation
preferences. Thanks for the source. Joe
Check out "C Programming: A Modern Approach" by K. N. King and "C: A
Reference Manual (5th edition)" by Harbison & Steele. These are two of
the best, most comprehensive books out there.


I just went to Amazon and got Harbison & Steele. I was stunned at how easy
it was, and I didn't have to pick through a bunch of garbage about C flat.
Makes a guy optimistic. Joe
May 10 '06 #14
On 4 May 2006 20:34:05 -0700, "Robert Gamble" <rg*******@gmail.com>
wrote:

<snip>
sscanf isn't the best tool for the job for a couple of reasons, not the
least of which is that trying to convert a number of too large a
magnitude results in undefined behavior.

The following program will read a line at a time from stdin and attempt
to convert it to an integer using the strtol function. If the line
contains any invalid characters, an error message is displayed and the
offending character is pointed out. If a range error occurs (the
number was too large/small to store in a long int), an appropriate
message is diaplayed. This version uses 'long int' and accepts
negative numbers, remove the minus sign from the string of allowed
characters if you just want to accept positive numbers. The code is a
little verbose since it implements error checking.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "-0123456789 \t\n")) == strlen(buf)) {
Note that this accepts things like "212-535-1000".

A line read by fgets can never include \n, although if this were split
off to a separate function as it probably should be you might want to
retain that for other usages. Or perhaps you want(ed) \r.
errno = 0;
l = strtol(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %ld\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');
A cleverer(?) way to do this is: printf ("%*s^", (int)s, "")
or if you like ("%*c", (int)s+1, '^');
or other obvious variations.
printf(" invalid character\n");
}
}
return 0;
}

The strspn function returns the number of characters in the input
string that are in the "allow" string, this must be the same as the
length of the string itself if all the characters are valid, otherwise
we print an error message displaying the location of the offending
character and continue.

The strtol function will skip leading whitespace and attempt to convert
the numeric part of the string to a long int. If an underflow or
overflow occurs then strtol returns LONG_MIN or LONG_MAX respectively
and sets errno to ERANGE. We just check errno and print an error if
appropriate, you could compare l to LONG_MIN or LONG_MAX to determine
the type of range error if desired.

strtol (and friends) will also return a pointer after the part of the
string it successfully converted; that's easier than getting your own
matching/validation logic to match exactly or even just right:
l = strtol (buf, &after, 10);
if( *after != '\0' ) /* wasn't (entirely) whitespace+number */
or
if( strspn (after, white) != strlen (after) )
if( after [strpsn (after, white)] != '\0' )
/* wasn't whitespace+number+whitespace */
etc.

<snip rest>

- David.Thompson1 at worldnet.att.net
May 14 '06 #15

Dave Thompson wrote:
On 4 May 2006 20:34:05 -0700, "Robert Gamble" <rg*******@gmail.com>
wrote:

<snip>
sscanf isn't the best tool for the job for a couple of reasons, not the
least of which is that trying to convert a number of too large a
magnitude results in undefined behavior.

The following program will read a line at a time from stdin and attempt
to convert it to an integer using the strtol function. If the line
contains any invalid characters, an error message is displayed and the
offending character is pointed out. If a range error occurs (the
number was too large/small to store in a long int), an appropriate
message is diaplayed. This version uses 'long int' and accepts
negative numbers, remove the minus sign from the string of allowed
characters if you just want to accept positive numbers. The code is a
little verbose since it implements error checking.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define BUF_MAX 80

int main (void) {
char buf[BUF_MAX];
long l;
size_t s;
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "-0123456789 \t\n")) == strlen(buf)) {
Note that this accepts things like "212-535-1000".


Good catch, I didn't think of that one but it still meets the OP's
criteria as stated (although I am pretty sure it's not the behavior the
OP would want).
I originally wrote this for unsigned longs and changed it at the last
minute, I don't remember why, and didn't take this into account.
A line read by fgets can never include \n, although if this were split
off to a separate function as it probably should be you might want to
retain that for other usages. Or perhaps you want(ed) \r.


You might want to review your documentation on the fgets function.
errno = 0;
l = strtol(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
printf("number read was %ld\n", l);
}
} else {
while(s--)
putchar(' ');
putchar('^');


A cleverer(?) way to do this is: printf ("%*s^", (int)s, "")
or if you like ("%*c", (int)s+1, '^');
or other obvious variations.


More clever perhaps, but less clear.
printf(" invalid character\n");
}
}
return 0;
}

The strspn function returns the number of characters in the input
string that are in the "allow" string, this must be the same as the
length of the string itself if all the characters are valid, otherwise
we print an error message displaying the location of the offending
character and continue.

The strtol function will skip leading whitespace and attempt to convert
the numeric part of the string to a long int. If an underflow or
overflow occurs then strtol returns LONG_MIN or LONG_MAX respectively
and sets errno to ERANGE. We just check errno and print an error if
appropriate, you could compare l to LONG_MIN or LONG_MAX to determine
the type of range error if desired.

strtol (and friends) will also return a pointer after the part of the
string it successfully converted; that's easier than getting your own
matching/validation logic to match exactly or even just right:
l = strtol (buf, &after, 10);
if( *after != '\0' ) /* wasn't (entirely) whitespace+number */
or
if( strspn (after, white) != strlen (after) )
if( after [strpsn (after, white)] != '\0' )
/* wasn't whitespace+number+whitespace */
etc.


Right. Given the deficiency you mentioned at the beginning of your
post, the above would probably be better solution.

Robert Gamble

May 15 '06 #16
On Thu, 4 May 2006 20:23:56 -0400, "Yogi_Bear_79" <no****@spamsux.com>
wrote:
I have the following code:

sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0;

It only partially works. If the user types a character other than 0-9 to
start the string it fails. However as long as the first character is an
integer it will allow letters in the following places

for Example:

H78 (fails as expected)
78 (works as expected)
7H8 ( doesn't fail as desired)


you have to write a sscanf like function
a better sscanf
May 15 '06 #17
On 14 May 2006 18:54:42 -0700, "Robert Gamble" <rg*******@gmail.com>
wrote:

Dave Thompson wrote:
On 4 May 2006 20:34:05 -0700, "Robert Gamble" <rg*******@gmail.com>
wrote: [about strspn for number-token including space \t \n]
A line read by fgets can never include \n, although if this were split
off to a separate function as it probably should be you might want to
retain that for other usages. Or perhaps you want(ed) \r.


You might want to review your documentation on the fgets function.

Aargh! Part of my brain was thinking but didn't finish getting to my
fingers: can't have \n _embedded_, only at the end, which I often
handle differently/specially -- probably including this case, although
as already noted I would probably have factored and (hopefully)
reusable "get line to buffer" and "parse number from buffer" instead
of "parse number from line" so avoiding the issue.
while(s--)
putchar(' ');
putchar('^');


A cleverer(?) way to do this is: printf ("%*s^", (int)s, "")
or if you like ("%*c", (int)s+1, '^');
or other obvious variations.


More clever perhaps, but less clear.

I for one can think of it either as "print n spaces and marker" where
the loop is (much) more obvious or as "print marker at column n" (like
Fortran or BASIC's 'tab' format) where the %* makes sense to me.

But objectively it is certainly rarer and less well known. Which may
well be sufficient reason to avoid it.

<snip other points>

- David.Thompson1 at worldnet.att.net
May 22 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Brent Lievers | last post by:
Greetings, I have a question about parsing a fixed-width integer from a string. Lines of data are being read from a file having a very strict column-delimited format. In my example below,...
3
by: whisper | last post by:
Hello: I am trying to write code to read in a bunch of lines from stdin, each containing a (variable) number of integers and writing each integer in a separate line to stdout. I came up the...
4
by: smshahriar | last post by:
Hi, I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00
10
by: baumann | last post by:
hi, 1) first test program code #include <stdio.h> int main(void) { char * file = "aaa 23 32 m 2.23 ammasd"; int i2,i3;
4
by: baumann | last post by:
hi all there has 2 program 1) the first test program code #include <stdio.h> int main(void) {
10
by: broeisi | last post by:
What advantages does sscanf offer over scanf? I had the following code: #include <stdio.h> #include <string.h> int main(void) { int start, finish, values;
4
by: lynx_ace | last post by:
Hi everyone. I need a little bit help here...I have an assignment and it is working fine until the last part which I can't solve. So here's the code in simple form #define maxlength 200 ...
7
by: Joachim Schmitz | last post by:
Hi folks What would be the expected and correct output of the following #include <stdio.h> int main (void) { char buffer1 = "(10,20,30)"; char buffer2 = "(10,20,30 )"; /* add two...
5
by: a | last post by:
After reading FAQ comp.lang.c section 12 and googling again, still there is no threads talking about reading a series of numbers. The input files, somehow structured, is exemplified below: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.