- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- C/C++ program
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 01:32 AM
тАО11-07-2006 01:32 AM
it should be in C/C++.
Assume this string as input,
string12.def
string41.abc
string19.cef
function should return me number
for example in string12 should return me int 12 for example 2 it should return me 41.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 02:17 AM
тАО11-07-2006 02:17 AM
Re: C/C++ program
you can loop through the string and isdigit test each char. If it is a digit, copy it to a second string and then atoi this second string to an integer.
Also see:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
- Tags:
- isdigit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 02:42 AM
тАО11-07-2006 02:42 AM
Solutionmy C is pretty lousy, so I am sure you can do better.
#include
int main( int argc, char *argv[] )
{
int a;
int c=0;
char IDATA[100];
char ODATA[100];
/* Get input data */
strcpy(IDATA,argv[1]);
/* Read through the string */
for (a=0;a<=(strlen(IDATA)-1);a++)
{
/* If it is a digit append to the Output */
if (isdigit(IDATA[a]))
{
ODATA[c]=IDATA[a];
c++;
}
}
printf("%s\n",IDATA);
printf("%d\n",atoi(ODATA));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 03:49 AM
тАО11-07-2006 03:49 AM
Re: C/C++ program
#include
#include
int parse_integer(char *instring)
{
int out = 0,i = 0;
char s[3][512];
while (i < 3) /* null the strings */
{
s[i] = '\0';
++i;
}
(void) sscanf(instring,
"%[^0-9]%[0-9]%[^0-9]",
s[0],s[1],s[2]);
if (strlen(s[2]) != 0) out = atoi(s[2]);
return(out);
} /* parse_integer */
Man scanf for details.
- Tags:
- scanf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 06:34 AM
тАО11-07-2006 06:34 AM
Re: C/C++ program
if (strlen(s[2]) != 0) out = atoi(s[2]);
SHOULD BE:
if (strlen(s[1]) != 0) out = atoi(s[1]);