repeat loop

This is a discussion on repeat loop within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <string.h> int main(int argc, char ** argv) { // Mainline Variable Declarations FILE * output = ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    repeat loop

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char ** argv)
    {
    // Mainline Variable Declarations
    FILE * output = stdout;
    FILE * input = stdin;
    
    float exposureTime; // Exposure time
    char aperture[4]; // Array of size 4
    int menu=0;
    
    	do
    	{
            // Prompt user for exposure time (number)
            fprintf(output,"Please enter menu number: ");
    
            // Input of exposure time
            fscanf(input,"%s",menu);
    	
    	if(menu == 1)
    	{
    	fprintf(output,"you have entered the help menu\n");
    	}
    	else if (menu==2)
    	{
    	fprintf(output,"you have entered the real menu\n");
    	}
    
    	}
    	while (menu != 0);
    return(0);
    
    }
    My loop aint workin properly? its supposed to let me keep enter a menu number untill it sees a 0??

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > fscanf(input,"&#37;s",menu);
    Did your compiler even warn you about this?
    If you're using a GCC based compiler, then add "-W -Wall -ansi -pedantic" to the compiler switches.

    menu is an int, so %d is the format, and you forgot the &
    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
    Aug 2007
    Posts
    270
    it compiled but didnt do anything so maybe thats the problem, oops thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Keep an eye on what your friends are up to as well.
    Help using fgets()
    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.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    63
    What in the hell is going here???????How many people post the same things?????????

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    As Salem says in the other thread, Same school... Or close enough

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Ohh this is fun, guess what may be a homework, "Ohh god I need submit tomm. Please help!!! "

    Look, here is a good tip for you all: Intendant your code, you will score more.

    ssharish

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    And why bother aliasing stdout and stdin? That's a waste of like ~8 bytes ! (assuming each FILE pointer is 4 bytes)

  9. #9
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by zacs7 View Post
    And why bother aliasing stdout and stdin? That's a waste of like ~8 bytes ! (assuming each FILE pointer is 4 bytes)
    You know what, i guess this is what their teacher is teaching them. Even his friends are using the same tech. Dunno why their teacher thought like.

    ssharish

  10. #10
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    I'm guessing it's for automated tests. In that case you just change two lines in the code and an automated test suite can run a few hundred tests from a file and print the result to another file, which can then be examined for the correct output.
    We had something similar at uni, 50&#37; of the marks were for the quality of the code, 50% for the automated tests.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    what happened to file redirection?

  12. #12
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by robwhit View Post
    what happened to file redirection?
    dunno, I'm just guessing...

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  13. #13
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    It's good if they understand files earlier on and the concept of stdin and stdout being files. Other than that, I don't know.

  14. #14
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    Hi taurus i see that u have wisely chosen to get advise from a forum for you uni assignment. ep100 to be more precise we are both on the same boat i need a lot of help too...reply please

  15. #15
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    HAHAHAHAH thats funny never saw that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 06:19 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

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