Thread: Data types and tokens .cpp

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    37

    Data types and tokens .cpp

    Code:
     // clapp strings.cpp : main project file.  #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string.h>  using namespace System;  int main(array<System::String ^> ^args) {     char SingleChar;     char mySentence[30] = "My name is Jeff"; /*can initialize a string when declared*/      char yetAnotherSentence[3] = "OR";     int intArr[30]; /* for perspective, will dwell on arrays later in class */          int lenOfMySent;      SingleChar = 'K';      printf("The text in mySentence is [%s]\n", mySentence);      mySentence[11] = 'S'; /* pick one slot in mySentence which is an array and modify */     mySentence[9] = 'S'; /* pick one slot in mySentence which is an array and modify */     printf("The text in mySentence after updating one alphabet is [%s]\n", mySentence);     printf("printing mySentence from 7'th slot onwards [%s]\n", mySentence + 7);      printf("scanf is a fragile way of reading a string \n \            1. One it doesn't read a sentence, will stop at the first space\n \            2. Will not check whether you've crossed the limit/ size for the string variable\n \            ");     printf("\nEnter a word(no space and <=29 in size)\n\tto read into mySentence using scanf :");     scanf("%s", mySentence); /*Look Ma, no & (in front of mySentence)*/     printf("The text in mySentence is with value from user is [%s]\n", mySentence);     scanf("%*c"); /*gobble up all extra space to get ready to read the next string*/     printf("\nEnter a sentence(<=29 in size)\n to read into mySentence using fgets :");     fgets(mySentence,29,stdin);     printf("The text in mySentence is with value from user with the newline is \n[%s]\n", mySentence);            lenOfMySent = strlen(mySentence); /* using the strlen in string.h library to get the length of the mySentence                                       includes the newline that the user entered to indicate done entering the string                                       but does not include the string delimitor                                       */      mySentence[lenOfMySent - 1] = '\0'; /*manually get rid of the newline that the user entered to indicate done entering the string*/     printf("The text in mySentence now that we've taken away the end newline is\n [%s]\n", mySentence);     printf("The length of mySentence now that we've taken away the end newline is [%d]\n", lenOfMySent);     printf("The sizeof of mySentence (the array) is [%d]\n", sizeof(mySentence));      printf("The sizeof of intArr (the array) is [%d]\n", sizeof(intArr));        system("pause");     return 0;   }
    If any one has a moment to coment on the use of .cpp tokens
    I would like to here from you
    in addition why is has the code between the brackets failed to word wrap vs continuous line?
    Last edited by AutoIt Addict; 07-19-2012 at 11:39 PM. Reason: word wrap/grammer

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    in addition why is has the code between the brackets failed to word wrap vs continuous line?
    You did not paste plain text. This is pretty obvious with all of the failed HTML like special characters and other weird accidents like =29

    Code:
    // clapp strings.cpp : main project file. #include "stdafx.h" #include &lt;
    stdio.h&gt;
    #include &lt;
    stdlib.h&gt;
    #include &lt;
    string.h&gt;
    using namespace System;
    int main(array&lt;
    System::String ^&gt;
    ^args) {
        char SingleChar;
        char mySentence[30] = "My name is Jeff";
        /*can initialize a string when declared*/  char yetAnotherSentence[3] = "OR";
        int intArr[30];
        /* for perspective, will dwell on arrays later in class */  int lenOfMySent;
        SingleChar = 'K';
        printf("The text in mySentence is [%s]\n", mySentence);
        mySentence[11] = 'S';
        /* pick one slot in mySentence which is an array and modify */ mySentence[9] = 'S';
        /* pick one slot in mySentence which is an array and modify */ printf("The text in mySentence after updating one alphabet is [%s]\n", mySentence);
        printf("printing mySentence from 7'th slot onwards [%s]\n", mySentence + 7);
        printf("scanf is a fragile way of reading a string \n \ 1. One it doesn't read a sentence, will stop at the first space\n \ 2. Will not check whether you've crossed the limit/ size for the string variable\n \ ");
        printf("\nEnter a word(no space and &lt;
        =29 in size)\n\tto read into mySentence using scanf :");
        scanf("%s", mySentence);
        /*Look Ma, no & (in front of mySentence)*/ printf("The text in mySentence is with value from user is [%s]\n", mySentence);
        scanf("%*c");
        /*gobble up all extra space to get ready to read the next string*/ printf("\nEnter a sentence(&lt;
        =29 in size)\n to read into mySentence using fgets :");
        fgets(mySentence,29,stdin);
        printf("The text in mySentence is with value from user with the newline is \n[%s]\n", mySentence);
        lenOfMySent = strlen(mySentence);
        /* using the strlen in string.h library to get the length of the mySentence includes the newline that the user entered to indicate done entering the string but does not include the string delimitor */  mySentence[lenOfMySent - 1] = '\0';
        /*manually get rid of the newline that the user entered to indicate done entering the string*/ printf("The text in mySentence now that we've taken away the end newline is\n [%s]\n", mySentence);
        printf("The length of mySentence now that we've taken away the end newline is [%d]\n", lenOfMySent);
        printf("The sizeof of mySentence (the array) is [%d]\n", sizeof(mySentence));
        printf("The sizeof of intArr (the array) is [%d]\n", sizeof(intArr));
        system("pause");
        return 0;
        
    }
    I guess it's better than nothing.

    What specifically do you want to know? "C++ tokens" are practically every bit of syntax.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This looks like a mix of C++/CLI and C.
    Pick a language first: C++/CLI, C++ or C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    I would like to narow it down to c++
    im not sure why it would be a mix i got the code from my instructor for c programming
    Ive compiled and executed the code using c++
    how would it be possible to use multiple languages in one script with out first declaring the switch?
    i have been instructed to select a compiler such as c++ to do the assignments
    she said there would be a program that will grade the assignments and maybe she wrote
    a special program for that
    where do you see the c source code
    I have never heard of cli do you mean clr console app?

    I just read the code that White flags posted and yes i see
    where code has been added that may be what you are talking about such as stdio.h&gt;
    Last edited by AutoIt Addict; 07-20-2012 at 01:19 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    All char, scanf, printf and fgets look like C to me.
    C++/CLI - Wikipedia, the free encyclopedia
    For reference, select a Win32 Console Project, not anything else when you create your project.

    And if you get code from your C instructor, then why do you bother with C++?
    If you want to learn C++, go a C++ course, not a C course.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    how would it be possible to use multiple languages in one script with out first declaring the switch?
    C++/CLI is a Microsoft technology. C++ with other features. It would be possible for an instructor to use CLI in a program without telling the students about it because Microsoft compilers support CLI seamlessly. Your instructor probably doesn't know the difference between this and C++, if this is the first time you've heard of C++/CLI.

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by Elysia View Post
    And if you get code from your C instructor, then why do you bother with C++?
    If you want to learn C++, go a C++ course, not a C course.
    If he wants to learn C++, he should go to a school outside of India or at least buddy up with the other Indians on this board. They seem to know where to go to learn and have their facts straight.

  8. #8
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    well when i signed up for the class i was unaware of all the differences
    I had a copy of microsoft visual studio 2010 but the trial version has expired
    correct me if i am wrong but i believe microsoft visual studio 2010 edits .c scourse
    Im going to renew the version Microsoft visual studio 2010 here in just a second
    if that's the case i will switch languages

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You are better off with Code::Blocks or a similar IDE that uses the GCC compiler if you're going to write C, than Visual Studio.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    ok i will select win 32 and see if that corrects the mix

  11. #11
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    ill check out code blocks for a free down load
    thanks
    Last edited by AutoIt Addict; 07-20-2012 at 12:48 PM.

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by AutoIt Addict View Post
    well when i signed up for the class i was unaware of all the differences
    I had a copy of microsoft visual studio 2010 but the trial version has expired
    correct me if i am wrong but i believe microsoft visual studio 2010 edits .c scourse
    Im going to renew the version Microsoft visual studio 2010 here in just a second
    if that's the case i will switch languages
    C++ is a superset of C. That is, standard C++ supports C features. Some of these features, like functions, are essential to programming as a whole. Other features of C++ can be ignored in a poorly structured C++ course. Look ahead in your course syllabus and see if classes and the STL are covered at all. In a poorly structured course, you will learn how to write C++ using C features and stuff like classes and the STL will not be taught at all.

    If you are in that situation there is no real point in staying in the course since the knowledge you will obtain is far from useful in the working world. Learn another language ...or something. Changing your tools will not help you improve the level of knowledge that you will receive.

  13. #13
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    code blocks looks pretty neat Im going to play with it for a bit and get back to you
    before i get started what kind of app would i select to confirm im writing in c

  14. #14
    Registered User
    Join Date
    Jul 2012
    Posts
    37
    thank you much white flags
    i think you may be right
    still going to check out code blocks it seem cool for now

  15. #15
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I'm confused. In your other thread, you said you had finite time to create a program that did certain things, and provided two very different programs in two separate posts, as if using them for reference. Now, you're saying that this was given to you by a "c programming" instructor, and you're trying to "correct" (read: modify) it to make it work.

    I hope you're not wasting our time asking us to help you modify code you found on the net to submit as an assignment without bothering to learn anything. That wouldn't be nice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Types
    By Sn0wcra5h in forum C Programming
    Replies: 1
    Last Post: 01-19-2010, 10:33 PM
  2. data types types...
    By gftmc in forum C++ Programming
    Replies: 3
    Last Post: 09-11-2006, 11:30 AM
  3. data types
    By 182 in forum C++ Programming
    Replies: 10
    Last Post: 02-18-2006, 05:24 AM
  4. data types
    By Draco in forum C Programming
    Replies: 7
    Last Post: 06-05-2002, 03:26 AM
  5. data types
    By wazilian in forum C Programming
    Replies: 1
    Last Post: 12-07-2001, 01:52 PM