Thread: string

  1. #1

    Question string

    Can somebody explian to me whty this function will
    return 7 ?

    int foo(char *s1, char *s2)
       int c=0, s, p, found;
       for (s=0; s1[s] != '\0'; s++)
          for (p=0, found=0; s2[p] != '\0'; p++)
             if (s2[p] == s1[s])
                found = 1;
          if (!found) c++;
       return c;
    If we were to make the following call to foo what value would it return?

    foo(“Asia Pacific”, “aeiou”);

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    The function returns the number of characters from the first argument that do not match any characters from the second argument. It should return 7:

    "Asia Pacific" == 12 (not including the nul)

    'i', 'a', 'a', 'i', 'i' == 5

    'A', 's', ' ', 'P', 'c', 'f', 'c' == 7

    Don't forget that a space is a character too.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM