Thread: if else problem

  1. #16
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    ok can you explain what a prototype is in simple terms for me plz.

  2. #17
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    Look at this code...

    If you actually try to call (i.e. use) a function before that function i defined, the compiler won't know if it's being called properly (i.e. that the right number and types of parameters are being passed and/or returned).

    In order to let the compiler know what to expect, you simply add the function name with it's parameter types and return type (if any). So for a function called swap, which takes two pointers to integers, but returns nothing, you should add the line

    void swap( int *, int * );

    at some point after your #include's, and before main.

  3. #18
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    am i able to use scanf to read characters from input and then only print certain things back to output? How do i specify what i want it to print back out. For example if i only want it to print everything except an A or something? At this stage i only know how to scanf in one letter at a time and print the same letter back out again:

    Code:
    #include <stdio.h>
    
               
       int main()
               
       {
       
          char a;
       
          scanf("%c", &a);
       
          printf("%c\n", a);
       
       }

  4. #19
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    this isnt working but am i on the right track with this?

    Code:
    #include <stdio.h>
    
               
       int main()
               
       {
       
          char a[200];
          while(a != '/0'){
             scanf("%c", &a);
          }
          if(a != 'l' || a != 'L'){
             printf("%c\n", a);
          }
       
       }

  5. #20
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    Best go to google.com and put scanf (or better) fgets into the search engine. You'll get everything you need from there.

    It's always worth doing a quick search there before placing questions to the forum.

  6. #21
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    Ok i see how i use the gets, but how do i specify what i want it NOT to print out. Is it like what i did in the code in my last post or how so i do it. If you could point me to a tute that explains that.. cool, otherwise an example would be nice.

    Heres the gets

    Code:
    #include <stdio.h>
    
               
       int main()
               
       {
          char my_string[500];
       
          gets(my_string);
       
          printf ("You typed: %s\n", my_string);
       
          return 0;
       }

  7. #22
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Ok i see how i use the gets
    Read these:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Once you have a line of text in an array, do something like:

    Code:
    - get the string length (strlen)
    - run a loop, from 0 to length-1
    - check each character against of unwanted character, and print it if it doesn't match
    
    len = strlen(input);
    for (i = 0; i < len; i++)
    {
      if (input[i] != 'W') putchar (input[i]);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #23
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    how come my or doesnt work?

    Code:
    #include <stdio.h>
    
       int len;
    
       int i;
               
       int main()
               
       {
          char my_string[500];
       
          gets(my_string);
       
       
          len = strlen(my_string);
       
          for (i = 0; i < len; i++)
          {
             if (my_string[i] != 'L' || my_string[i] != 'l') putchar(my_string[i]);
          }
       
          return 0;
       }

  9. #24
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >how come my or doesnt work?

    It works fine. But you probably mean to use &&.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #25
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    I have had a look at what the FAQ has to say about strcmp() but i still dont really know how i use it, or even if its what i need to use. I need to be able to look at whole words and not just letters as i have got above. Can someone please show me an example of this.

    i tried this:

    Code:
    if (my_string[i] != 'something') putchar(my_string[i]);
    but it wont work coz it only looks at individual characters.

  11. #26
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Don't bother too much with tutorials most of them tell you how to do everything the wrong way.
    Go and buy a good reference book.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM