how to find numbers in a char array.

This is a discussion on how to find numbers in a char array. within the C Programming forums, part of the General Programming Boards category; 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.....

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,261
    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%.

  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
    21,636
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10:05 AM
  4. Replies: 3
    Last Post: 11-17-2008, 11:36 AM
  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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21