simple input and string manipulation question

This is a discussion on simple input and string manipulation question within the C Programming forums, part of the General Programming Boards category; Hi guys, these are probably two fundamental questions but as I'm getting back into programming after 8 years its hard ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    simple input and string manipulation question

    Hi guys,

    these are probably two fundamental questions but as I'm getting back into programming after 8 years its hard to rack my brain and also hard, without reference, to make head nore tale of some of the search results I've gotten

    q1.) In C is there a simple way of controlling whehter the program only reads in numeric values and ignores alpha?

    I tried to use the atoi boolean test but it sometimes messed up (my code probably dodgy) and was a pain in the neck having to add the checks after each input field.

    q2.) again fundamental sorry. The tool I am doing reads in potentially up to 16 names. With the loops I have got I want to simply have the input placed into a variable which is then copied to a string array

    e.g

    char interface[10];
    char interface_array[16][10];
    int count[16];

    for (count=0; count!=16; count++)
    {
    printf("\nPlease enter the %d interface name >",count);
    scanf("%s", interface);
    }


    Ok so this is a poor example but basically I need something after the scanf to copy interface value to the array. The line could then be recalled later.

    Sorry its such a simple question but please can someone help?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    For your first question... this is kinda a tricky question, you'll have to elaborate a bit more on what you want to do.

    Well, for your second question, I'd probably get aorund it by just scanning straignt into the string array...
    Code:
    for (count=0; count!=16; count++) 
    { 
     printf("\nPlease enter the %d interface name >",count); 
     scanf("%s", interface_array[count]); 
    }
    And for your code, please use code tags, instead of quote tags. Code preserves spacing, and uses standard-width font, which makes code much easier to read in it.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Hopefully simple question, input streams
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2006, 01:59 PM

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