Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C Programming code to build an echo varient that hopefully can be used in WinXP

C Programming code to build an echo varient that hopefully can be used in WinXP

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomtoolstutorial
16 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Yes, all code must be contained in a function. you can put it all in main for a simple program, but for more complex problems you should create other functions that can be called with different parameter values. The documentation explains it clearly.

    J Offline
    J Offline
    jackngill
    wrote on last edited by
    #7

    Thanks Richard, I have edited/amended my first post to reflect what you have said. Yes small programs are a good place to start many thanks!

    L 1 Reply Last reply
    0
    • J jackngill

      Thanks Richard, I have edited/amended my first post to reflect what you have said. Yes small programs are a good place to start many thanks!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #8

      You have another function inside main, which is also wrong:

      int echo(){
      char input[80];

      Each function must stand alone in the main part of the source file:

      int echo()
      {
      // code for the echo function
      }

      int main()
      {
      // code for main, including any calls to echo
      }

      And get rid of those goto statements, that is really bad practice in modern programming. As I suggested above, get a copy of K & R and spend time learning the language properly. Trying to learn by questions here will take ten times as long, and not be comprehensive.

      J 1 Reply Last reply
      0
      • L Lost User

        You have another function inside main, which is also wrong:

        int echo(){
        char input[80];

        Each function must stand alone in the main part of the source file:

        int echo()
        {
        // code for the echo function
        }

        int main()
        {
        // code for main, including any calls to echo
        }

        And get rid of those goto statements, that is really bad practice in modern programming. As I suggested above, get a copy of K & R and spend time learning the language properly. Trying to learn by questions here will take ten times as long, and not be comprehensive.

        J Offline
        J Offline
        jackngill
        wrote on last edited by
        #9

        Hi Richard, Sorry for not being attentive but I have been trying to find the book that you referred to in respect of "C" programming & I have finally sourced a copy albeit in PDF format but I have none-the-less found it, so I've got it now. Also I have been viewing a u-tube video which I have downloaded from here: https://www.youtube.com/watch?v=KJgsSFOSQv0[^] Only because I am the type of person if I can see it visually I tend to retain the info a bit better as I am not the sharpest tool in the toolbox if you know what I mean. The narrator in the video mentions code::blocks which comes with IDE text editor & compiler to run the programs I selected the portable version with mingw to get started I will install tommorrow & give test run I have also been listening to some of the examples on the utube video. I may be able to break my code sample down into say 3 stages and run the code in Code::Blocks to check if the code is somewhere near possibly (Test-running)? When you refer to the goto statements as being very bad practice in modern programming the only reason I opted to use these was because batch scripting is familair ground to me & Batch uses goto :labels therein quite a lot. Also one of the web-sites stated that goto statements are bad because of the dangers of spaghetti code, however they went onto say that if used sparingly & in the case of flag usage e.g. & only confined to purely isolated cases (like flags -X) they were, (although frowned upon) were permissable. If I could use them until I acquire the necessary alternative skillset would it be okay for now given my obvious limitations. I could then interchange the new code with the goto code at a later date or is there another reason which I am missing here that I should not be using them, like they will not compile etc? I will also attempt to amend the 1st post code with amended curly brackets. Best Regards

        L 1 Reply Last reply
        0
        • J jackngill

          Hi Richard, Sorry for not being attentive but I have been trying to find the book that you referred to in respect of "C" programming & I have finally sourced a copy albeit in PDF format but I have none-the-less found it, so I've got it now. Also I have been viewing a u-tube video which I have downloaded from here: https://www.youtube.com/watch?v=KJgsSFOSQv0[^] Only because I am the type of person if I can see it visually I tend to retain the info a bit better as I am not the sharpest tool in the toolbox if you know what I mean. The narrator in the video mentions code::blocks which comes with IDE text editor & compiler to run the programs I selected the portable version with mingw to get started I will install tommorrow & give test run I have also been listening to some of the examples on the utube video. I may be able to break my code sample down into say 3 stages and run the code in Code::Blocks to check if the code is somewhere near possibly (Test-running)? When you refer to the goto statements as being very bad practice in modern programming the only reason I opted to use these was because batch scripting is familair ground to me & Batch uses goto :labels therein quite a lot. Also one of the web-sites stated that goto statements are bad because of the dangers of spaghetti code, however they went onto say that if used sparingly & in the case of flag usage e.g. & only confined to purely isolated cases (like flags -X) they were, (although frowned upon) were permissable. If I could use them until I acquire the necessary alternative skillset would it be okay for now given my obvious limitations. I could then interchange the new code with the goto code at a later date or is there another reason which I am missing here that I should not be using them, like they will not compile etc? I will also attempt to amend the 1st post code with amended curly brackets. Best Regards

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          jackngill wrote:

          I have been trying to find the book

          Amazon has it The C Programming Language (2nd Edition): Amazon.co.uk: Kernighan, Brian, Ritchie, Dennis: 8601410794231: Books[^].

          jackngill wrote:

          The narrator in the video mentions code::blocks

          I would recommend Visual Studio 2019 from Microsoft. It's free and runs natively, so does not require mingw.

          jackngill wrote:

          If I could use them (goto) until I acquire the necessary alternative skillset

          If you do it properly in the first place you will find there is no need for them. Whilst they will always compile they really are best avoided, especially as a new boy.

          J 1 Reply Last reply
          0
          • J jackngill

            Hi Richard :thumbsup: Thanks for sharing your experience & advice it has ironed out quite a few wrinkles- I will Kinda work last to the first of your quotes or in reverse order.

            Quote:

            If you do it properly in the first place you will find there is no need for them. Whilst they will always compile they really are best avoided, especially as a new boy.

            I see, what about if I used a "if" "else" statement like e.g. if the user types or stipulates the "-x" flag with "ECO" then "ECO" removes the CRLF/EOL, "else" the user fails to input "-x" flag then "ECO" just echo's one line of text to the screen in the same fashion the normal echo statement does? If this is a suitable alternative I will work on amending the code?

            Quote:

            I would recommend Visual Studio 2019 from Microsoft. It's free and runs natively, so does not require mingw.

            I have downloaded the community edition of Visual Studio 2019 it seems to be the free version, will I need additional software to convert code (ECO.h) to EXE/COM once I have corrected all my errors? and last but not least... (Edit) Oop's It does not seem I will be able to use the 2019 version as it is asking for Dot net vers 4.6 which is a bridge too far for winXPSP3 I think Vers 4.0 was the last for XP I will look for earlier vers compatable with XP.

            Quote:

            Amazon has it The C Programming Language (2nd Edition): Amazon.co.uk: Kernighan, Brian, Ritchie, Dennis: 8601410794231: Books[^].

            It's okay I have managed to get hold of a copy "The C Programming Language" & will inwardly digest & will be good for referencing study. Best Regards David

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #11

            jackngill wrote:

            I see, what about if I used a "if" "else" statement

            Exactly right, and you can eliminate any requirement for goto by correct use of if/else, while, switch, etc. My point was (sort of) do it the right way now, and life becomes much easier. Writing code that you know is poor or less efficient with a mental note to fix it in the future is usually a path to problems in the future.

            jackngill wrote:

            will I need additional software

            No, Visual Studio includes all the components necessary to build source code into executables. BTW .COM files were abandoned years ago. Just make sure you include the right components (Visual C++ package) for building C/C++ programs. The same integrated compiler will build code written in either language.

            J 1 Reply Last reply
            0
            • L Lost User

              jackngill wrote:

              I have been trying to find the book

              Amazon has it The C Programming Language (2nd Edition): Amazon.co.uk: Kernighan, Brian, Ritchie, Dennis: 8601410794231: Books[^].

              jackngill wrote:

              The narrator in the video mentions code::blocks

              I would recommend Visual Studio 2019 from Microsoft. It's free and runs natively, so does not require mingw.

              jackngill wrote:

              If I could use them (goto) until I acquire the necessary alternative skillset

              If you do it properly in the first place you will find there is no need for them. Whilst they will always compile they really are best avoided, especially as a new boy.

              J Offline
              J Offline
              jackngill
              wrote on last edited by
              #12

              Hi Richard :thumbsup: Thanks for sharing your experience & advice it has ironed out quite a few wrinkles- I will Kinda work last to the first of your quotes or in reverse order.

              Quote:

              If you do it properly in the first place you will find there is no need for them. Whilst they will always compile they really are best avoided, especially as a new boy.

              I see, what about if I used a "if" "else" statement like e.g. if the user types or stipulates the "-x" flag with "ECO" then "ECO" removes the CRLF/EOL, "else" the user fails to input "-x" flag then "ECO" just echo's one line of text to the screen in the same fashion the normal echo statement does? If this is a suitable alternative I will work on amending the code?

              Quote:

              I would recommend Visual Studio 2019 from Microsoft. It's free and runs natively, so does not require mingw.

              I have downloaded the community edition of Visual Studio 2019 it seems to be the free version, will I need additional software to convert code (ECO.h) to EXE/COM once I have corrected all my errors? and last but not least... (Edit) Oop's It does not seem I will be able to use the 2019 version as it is asking for Dot net vers 4.6 which is a bridge too far for winXPSP3 I think Vers 4.0 was the last for XP I will look for earlier vers compatable with XP.

              Quote:

              Amazon has it The C Programming Language (2nd Edition): Amazon.co.uk: Kernighan, Brian, Ritchie, Dennis: 8601410794231: Books[^].

              It's okay I have managed to get hold of a copy "The C Programming Language" & will inwardly digest & will be good for referencing study. Best Regards David

              L 1 Reply Last reply
              0
              • L Lost User

                jackngill wrote:

                I see, what about if I used a "if" "else" statement

                Exactly right, and you can eliminate any requirement for goto by correct use of if/else, while, switch, etc. My point was (sort of) do it the right way now, and life becomes much easier. Writing code that you know is poor or less efficient with a mental note to fix it in the future is usually a path to problems in the future.

                jackngill wrote:

                will I need additional software

                No, Visual Studio includes all the components necessary to build source code into executables. BTW .COM files were abandoned years ago. Just make sure you include the right components (Visual C++ package) for building C/C++ programs. The same integrated compiler will build code written in either language.

                J Offline
                J Offline
                jackngill
                wrote on last edited by
                #13

                It seems that one of my previous replies/posts is under review for possible spam or at least at my end it is showing so. I do not understand why this is I have been reflecting over the content trying to think what may have triggered this, I'm not sure what would cause this reaction. Perhaps I need to contact a mod for clarification. I think, I will need to check at further length Visual Studio 2017 works with XP but it depends on what vers of Dotnet is required I think Dot net framework Vers 4.0 was the last for XP

                L 1 Reply Last reply
                0
                • J jackngill

                  It seems that one of my previous replies/posts is under review for possible spam or at least at my end it is showing so. I do not understand why this is I have been reflecting over the content trying to think what may have triggered this, I'm not sure what would cause this reaction. Perhaps I need to contact a mod for clarification. I think, I will need to check at further length Visual Studio 2017 works with XP but it depends on what vers of Dotnet is required I think Dot net framework Vers 4.0 was the last for XP

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #14

                  Nothing showing here. When and if it does happen, just be patient. The automatic spam checker holds "suspect" messages in a queue. They are then reviewed by one of the many moderators here, and accepted or rejected as appropriate. Your messages may get picked up for spurious reasons, but it is a fairly intelligent system and will improve once it recognises you.

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    Nothing showing here. When and if it does happen, just be patient. The automatic spam checker holds "suspect" messages in a queue. They are then reviewed by one of the many moderators here, and accepted or rejected as appropriate. Your messages may get picked up for spurious reasons, but it is a fairly intelligent system and will improve once it recognises you.

                    J Offline
                    J Offline
                    jackngill
                    wrote on last edited by
                    #15

                    :thumbsup:Richard, Yes decided to leave the site alone for a while to allow the spam-bot thing do it's thing. I took the oppertunity to look into/do some research into Visual Studio & which version would be suitable with windows XP. This info may help others who might find themselves here. The version you can install is dictated in the main by the Dot Net Framework version as Visual Studio requires the relevant dot net framework installed which in the case of Windows XP (last DotNet for XP) "DotNet framework version 4.0" it needs to be installed with your OS. Now I have trawled a few sites looking at what the latest version would be for Windows XPSP3 & it is "Visual Studio 2010" which is going back some when the current vers at the time of writing is 2019. I have found it quite difficult to grab a 2010 version as we are talking old School but I elected to download an offline iso version called OFFLINESOFTWARES.COM_VS2010Express.iso. Not content with just downloading it (which incidently is 693Mb) I have scanned the iso with 2 virus checkers to check for malware & viruses, I do not have any affiliation with the VStudio website it was just the first one which I was successful in downloading it from. I would post the link but I will need to check if it is permissable here first. I think fully installed needs 2.2Gb of your HDD space. Anyway My little rant over where/which Visual Studio 2010 which may or may not help others now is concluded. I think I will need to clear some HDD space to install it as it needs a fair amount of space. Okay "if" "Else" it is then re not using goto statements:thumbsup: I have been undertaking some house keeping as I needed to clear some hard drive space to install Visual Studio Vers 2010. I have done so but it seems to be defaulting to C++ rather than "C" Will the editor accept "C" code rather than C++? best Regards

                    J 1 Reply Last reply
                    0
                    • J jackngill

                      :thumbsup:Richard, Yes decided to leave the site alone for a while to allow the spam-bot thing do it's thing. I took the oppertunity to look into/do some research into Visual Studio & which version would be suitable with windows XP. This info may help others who might find themselves here. The version you can install is dictated in the main by the Dot Net Framework version as Visual Studio requires the relevant dot net framework installed which in the case of Windows XP (last DotNet for XP) "DotNet framework version 4.0" it needs to be installed with your OS. Now I have trawled a few sites looking at what the latest version would be for Windows XPSP3 & it is "Visual Studio 2010" which is going back some when the current vers at the time of writing is 2019. I have found it quite difficult to grab a 2010 version as we are talking old School but I elected to download an offline iso version called OFFLINESOFTWARES.COM_VS2010Express.iso. Not content with just downloading it (which incidently is 693Mb) I have scanned the iso with 2 virus checkers to check for malware & viruses, I do not have any affiliation with the VStudio website it was just the first one which I was successful in downloading it from. I would post the link but I will need to check if it is permissable here first. I think fully installed needs 2.2Gb of your HDD space. Anyway My little rant over where/which Visual Studio 2010 which may or may not help others now is concluded. I think I will need to clear some HDD space to install it as it needs a fair amount of space. Okay "if" "Else" it is then re not using goto statements:thumbsup: I have been undertaking some house keeping as I needed to clear some hard drive space to install Visual Studio Vers 2010. I have done so but it seems to be defaulting to C++ rather than "C" Will the editor accept "C" code rather than C++? best Regards

                      J Offline
                      J Offline
                      jackngill
                      wrote on last edited by
                      #16

                      Hi Richard:thumbsup: I think because I am working on a EOL OS (XP) I have been having lots of problems installing Visual Studio 2010 I think the problems exist because the OS & the development of VStudio 2010 have not made any progress since its conception & I think that is why it is not working. I have alternatively installed Code::Blocks with some minor glitchs & needing some additional files to run under XP but it seems to be working correctly. I went for the portable install so that if it is no good for some reason I can easily ditch. Code::Blocks seems to have continuing development for XP so it has the advantage of update progression. I will keep you posted re developments Best Regards :-D

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups