Thread: Reading in data from Text file

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    Umm . . . what? MSVC can't create code that is very portable. Executables are by their very nature not very portable. But at least GCC can compile the same code under Windows and Linux.
    Come on, like it really matters. You're just adding salt to the wound.
    It's a shame it won't work under other operating systems (though it might work under Wine, which would negate that argument), but that doesn't mean it's a bad IDE compared to Dev-C++/GCC.

    It's quite a bit more complicated. There are extra clicks involved and extra files.
    Like it really matters. Are you that lazy that you can't create a new project?

    Dev-C++. mingw is a Windows port of GCC. Dev-C++ is a GUI (written in Delphi ) that can run GCC, the mingw or the cygwin ports.
    Right, I mix that up because I don't use either of them...

    Food for thought -- GCC might not support narrowing warnings, but MSVC doesn't support long doubles, AFAIK. http://www.thescripts.com/forum/thread61148.html
    That's more important, I think; the warning isn't strictly required, but long doubles are for C99.
    But who cares about C99? C++ is superior to C, can do everything C can and more, and it fully supports C++, to an extent far better than C89 and C99.
    Come on... You can compile C code under 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.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    ok sooo what does the " buffer, sizeof(buffer" do
    You just used it yourself:
    Code:
    fgets(buf,sizeof(buf),f);
    I just happened to use a variable called "buffer" instead of "buf".

    lol thisss iss rather hardd
    Yes, there are quite a few things going on here . . . .

    [edit]
    Come on, like it really matters. You're just adding salt to the wound.
    It's a shame it won't work under other operating systems (though it might work under Wine, which would negate that argument), but that doesn't mean it's a bad IDE compared to Dev-C++/GCC.
    Whether the IDE works under Wine or not, you can only generate Windows executables. I can wine GCC, and generate Win32 executables (or use a Linux port of mingw ); or generate Linux executables directly. That's quite different. And I'm sorry if you were insulted.

    Like it really matters. Are you that lazy that you can't create a new project?
    It's not a question of laziness -- it's whether you know how or not. Projects are just one other step you have to learn to create a Hello, World program with MSVC.

    But who cares about C99? C++ is superior to C, can do everything C can and more, and it fully supports C++, to an extent far better than C89 and C99.
    Not everything -- see below.

    Come on... You can compile C code under C++.
    No you can't. There are a few differences. Someone (Dave_Sinkula, I think) has a list that they link to occasionally.

    For example -- long doubles! They don't exist in C++. Do you know what kind of a range you can represent with a long double? Huge.

    Another example: assignments from void pointers. You need a cast in C++, which means you can't compile perfectly valid C as C++ all of the time. [/edit]
    Last edited by dwks; 03-05-2008 at 02:57 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    ok im finding all this really hard to take in is there any tutorials or any reading material besides
    http://www.cprogramming.com/tutorial/c/lesson10.html . because atm i seem lost

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    Whether the IDE works under Wine or not, you can only generate Windows executables. I can wine GCC, and generate Win32 executables (or use a Linux port of mingw ); or generate Linux executables directly. That's quite different. And I'm sorry if you were insulted.
    It's a limitation you have to live with. You can't have everything.
    Linux uses the "odd" format
    (Btw, I'm just typing that tease you )

    It's not a question of laziness -- it's whether you know how or not. Projects are just one other step you have to learn to create a Hello, World program with MSVC.
    But ehhh... you know, learn how to create a project, veeeeeeeeeeeeeeeeeeeeery easy and you're underway.

    No you can't. There are a few differences. Someone (Dave_Sinkula, I think) has a list that they link to occasionally.
    But I never mentioned it would compile without a few code changes. But you do everything you can in C in C++, so it works. You can use C++ for all your needs if you want.

    For example -- long doubles! They don't exist in C++. Do you know what kind of a range you can represent with a long double? Huge.
    Better use SSE instead

    Quote Originally Posted by fortune2k View Post
    ok im finding all this really hard to take in is there any tutorials or any reading material besides
    http://www.cprogramming.com/tutorial/c/lesson10.html . because atm i seem lost
    I'm not sure what you're confused about? Reading? Copying? Truncating? Working with strings?
    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.

  5. #20
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    well i think im missing out on some knowledge i think i need to re learn the basics i only had a lecture on it the other day and most of the stuff wasnt coverd i kinda know reading and working with basic strings i think its the copying and truncating which i think i need to learn

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You understand that strings are basically an array with chars, with the last element in the array being '\0', right? The '\0' means "this is the end of the string." So we can abuse that to "truncate" the string. By doing that, all functions will think the string ends there, so we can easily copy just a part of the string using strcpy.
    We can also use pointers to specify a start. Since a pointer can point anywhere in memory, we can just set it to a position within the string. When you pass that pointer to functions, they'll think the string starts where that pointer points (inside the string). Makes sense?
    Therefore, we can do something like this:

    Code:
    char mystr[] = "This is my test string";
    char temp[50];
    char* p = NULL;
    while ( p = strstr(mystr, " ") ) /* Find the first space */
    {
    	*p = '\0'; /* Truncate the string */
    	strcpy(temp, mystr); /* Copy part of word to new buffer */
    	printf("%s ", temp); /* Print temporary buffer plus a space */
    	p++; /* Advance the position in the string to the next character */
    	/* Rinse and repeat! */
    }
    This is a simple example.
    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.

  7. #22
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    ok sooo your program is looking for spaces in the line and splitting them up ok im gonna re read bout strings ty for help ill get back to u onm my progress

  8. #23
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    But I never mentioned it would compile without a few code changes. But you do everything you can in C in C++, so it works. You can use C++ for all your needs if you want.
    Apparently, both C and C++ are Turing-complete. Even assembly is. So everything you can do with C++, you can also do with assembly.

    That doesn't mean you should.

    What about restrict? That's a C99 keyword that has no equivalent in C++.
    C99 introduces a new keyword, restrict that can only be applied to pointers. It indicates that, during the scope of that pointer declaration, all data accessed through it will be accessed only through that pointer but not through any other pointer. By declaring pointers as restricted, the programmer states that they do not refer to the same object.
    http://www.informit.com/guides/conte...lus&seqNum=215

    Anyway . . . an argument about whether C99 or C++ is better is pointless, and promises to be very long. How did we get there, anyway? Oh, right, because MSVC can't handle some features of C99.

    It's a limitation you have to live with. You can't have everything.
    MSVC's ability to generate executable code only for Windows is a limitation I have to live with? . . . that's why I use GCC . . . .

    I think, basically, MSVC is good because it can compile Windows-specific programs, and it has some minor advantages such as supporting other warnings. GCC is good because it's portable, open source, and supports more of other standards, such as C99 and POSIX. (That's all we've come up with so far, anyway.)

    Which IDE is better for beginners is debatable, and really there's probably little difference. Sure, you don't have to use projects in Dev-C++ and MSVC might have a "more user-friendly" interface, but we use what we're used to, whatever that might be.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The point being that C++ can do almost everything C can do (except for some C99 stuff), and more than C can, so I find little point in using C99 or C89 over C++, and I don't code for Linux or any other OS, so I find that Visual Studio is all the better than GCC.
    If you want to compile for another OS, just use another compiler to compile the code.
    Visual Studio can produce portable code, as well.

    Again, which GUI is better for newbies is debatable, but I'm all for more warnings, sleeker GUI and such, than cross-platform, open-source.
    They're both free anyway.
    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. #25
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Visual Studio can produce portable code, as well.
    I don't know why you keep saying this. My definition of "portable" means that it works on at least two different systems, say Windows and Mac. MSVC can generate code for only one platform: Windows. At least as far as I know.

    Again, which GUI is better for newbies is debatable, but I'm all for more warnings, sleeker GUI and such, than cross-platform, open-source.
    They're both free anyway.
    Depends on your definition of "free". http://www.gnu.org/philosophy/free-sw.html

    (I would likely have said "free" as well, BTW.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    I don't know why you keep saying this. My definition of "portable" means that it works on at least two different systems, say Windows and Mac. MSVC can generate code for only one platform: Windows. At least as far as I know.
    My definition of portable is that it can create code that will compile across all C++ compilers without hacks and ifdefs.

    Depends on your definition of "free". http://www.gnu.org/philosophy/free-sw.html

    (I would likely have said "free" as well, BTW.)
    I really care little about GNU and open source. Sure, it's great, but it's not a requirement for a software to be free. As long as the software works, does its purpose, and I can get help when I need it, it's enough for me.
    If it costs nothing, then it's free.
    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.

  12. #27
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    I have one and only one comment to add to the compiler "battle" going on here.
    best IDE ever
    Oh and what if i go crazy and decide to implement the entire "feature" set of the MSVC family of libraries for gcc, as a lifetime project, and then gcc will compile everything!
    Gcc , the Universe and Everything!
    However i don't think i'd stay alive long enough to complete such a project
    micro$oft joke
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by xuftugulus View Post
    best IDE ever
    Oh and what if i go crazy and decide to implement the entire "feature" set of the MSVC family of libraries for gcc, as a lifetime project, and then gcc will compile everything!
    Gcc , the Universe and Everything!
    I'll only convert if they add a fancy GUI and decide to add narrowing warnings.
    Oh and if they could make everything bug free with a fluffy GUI, I'd convert in an instant.
    I don't really care who makes it, just as long as it has what I want, what I like.
    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.

  14. #29
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I have one and only one comment to add to the compiler "battle" going on here.
    best IDE ever
    Yes, we really should be arguing about all IDEs, not just Windows ones!

    Gcc , the Universe and Everything!
    http://cboard.cprogramming.com/showp...4&postcount=87

    My definition of portable is that it can create code that will compile across all C++ compilers without hacks and ifdefs.
    MSVC, your compiler, can generate portable C++ source code? What are you talking about? If that is what you meant, it's certainly not what a compiler usually does . . . .

    I'll only convert if they add a fancy GUI and decide to add narrowing warnings.
    Fancy GUI is covered, by Code::Blocks, for example. If you like narrowing warnings so much, why don't you add support for them yourself?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    MSVC, your compiler, can generate portable C++ source code? What are you talking about? If that is what you meant, it's certainly not what a compiler usually does . . . .
    It my turn to be confused now. What are you talking about?
    I'm saying that it's a standards-compliant compiler that require you to write code in standards compliant way so that it will compile without modifications on other compilers.
    This is unlike MSVC6, whose standards compliance was very poor. Code written for that compiler did not compile in other compilers or vice versa.

    Fancy GUI is covered, by Code::Blocks, for example. If you like narrowing warnings so much, why don't you add support for them yourself?
    Not really a compiler writer... such things are beyond my current experience.
    And what would the compiler be written in? C?

    Code::Blocks is a nice GUI, I can see. I like it.
    Of course, it depends on the GCC compiler, and that's bad.
    I don't know much about the GUI, how it handles IntelliSense, debug functions, compiler availability, options inside the GUI and not command lines, etc.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading data from a text file
    By Dark_Phoenix in forum C++ Programming
    Replies: 8
    Last Post: 06-30-2008, 02:30 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 07:13 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM