Thread: how to find numbers in a char array.

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    32

    how to find numbers in a char array.

    hai..
    how to find numbers in a char array like
    Ex: [a,1,b,2,c,3] = [a,b,c,1,2,3]
    Ex2: [a1,b2,c3] = [a,b,c,1,2,3]

    thanks..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Post something in an actual char array.

    Code:
    char x[] = "abc123";
    char y[] = " [a,b,c,1,2,3]";
    Have different answers.

    You need to show us exactly how your notation maps to actual stored characters in a program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    32
    a char array contain ['a','1','b','2','c','3','d'] means output should be sort the alphabets and numbers like => abcd123
    so I have to find the integer in char array how could I separate that.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Sort the array. All the digits will be in a group (either before or after the letters, depending on character set supported by your compiler and host system). Shift that group to the end of the array if it is not already there.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    32
    But how I can identify number and character in c?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you want to identify if a char is a digit, #include <ctype.h> and use isdigit, or check that the char is between '0' and '9' inclusive.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to find the smallest 5 numbers in an array?
    By atac in forum C Programming
    Replies: 4
    Last Post: 08-28-2012, 02:27 AM
  2. To Find Largest Consecutive Sum Of Numbers In 1D Array
    By chottachatri in forum C Programming
    Replies: 22
    Last Post: 07-10-2011, 01:43 PM
  3. find and replace duplicate numbers in array
    By Cathalo in forum C++ Programming
    Replies: 5
    Last Post: 02-17-2009, 11:05 AM
  4. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  5. Find '&' character in char array?
    By tidemann in forum C Programming
    Replies: 7
    Last Post: 10-19-2006, 05:04 AM

Tags for this Thread