• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Of these, which is the highest version?

As far as I know, VS Ultimate has everything but I could be completely and totally wrong, I don't use VS all that often myself. One thing you might want to consider, if you're new to programming in general and c++ in particular is to have a go at writing some small programs with just a text editor and a command line to compile. You'll get a better feel for how code hangs together and it will make more sense straight off the bat. Visual Studio is a great IDE but I think it obscures too much of the under the hood stuff and can result in people getting through years of programming in college and then falling apart the second a project they're working on breaks or needs to be built with a makefile.

Visual Studio uses it's own compiler and so it can function as a standalone thing but most editors are just editors that use an external compiler. If you're running windows you could have a go at installing

MinGW:
http://www.mingw.org/wiki/Getting_Started

And then a decent text editor like Notepad++:
http://notepad-plus-plus.org/

And then just follow a really simple tutorial, I'm not sure where to go for good ones online, your best bet is probably a good book, but this one covers setting up compiling and writing a first program without the use of a complex IDE:
http://grandfiles.com/tutorials/mingw/index.html

After you're happy that you get the basics of doing that knock yourself out with VS but I think it can be a bit too much of an abstraction to begin with.
 

KorrZ

Member
Can anyone point me to a good book/online reference to using DirectX with C++? I'd like to finally get out of making purely console based applications finally, but am not really sure where to start. Thanks in advance.
 
Kind of going a little off topic, but...

Visual Studio is a great IDE but I think it obscures too much of the under the hood stuff and can result in people getting through years of programming in college and then falling apart the second a project they're working on breaks or needs to be built with a makefile.

This is me and I'm scared as shit of when it's going to happen.

I went to school to be a developer, but worked as a sys admin for a small place for almost 10 years. I did small programming projects here and there, but nothing too involved.

In March I started working for a friend of a friend that started an IT business. His idea is to eventually having me run a programming side of the business once we get the funding in place. There are so many gaps in my knowledge it's not funny! I definitely need to find some resources to help me fill in these gaps. Fortunately, I'm also a pretty good sys admin and have been able to handle server management, networking, etc at clients.

The GAF programming challenge this week kind of forced me to learn recursive backtracking, which is one of many algorithms in said knowledge gaps.

Anyway, I guess what I'm asking is if anyone might have any suggestions of where I can start to become more well rounded. My experience consists of web apps, database interaction with .net, and various small scale c++, Java, and C# apps.
 

The Lamp

Member
I have a question about a something in C.

I'm doing an assignment and I wanted to make a string for someone's name.

Initialized it as

char name[50];

Now at the end of my function I want to make something called winner_name take on the value of whatever name is.

But when I try to do:

"winner_name = name;"

It tells me "incompatible types in assignment".

How can I change a string to reflect new contents?
 

Pirabear

Banned
Probably an idiotic and vague question but, how exactly do you study/practice programming? I'm currently taking a class in C, and while I can gather how to do simple things and how functions work, I feel overwhelmed and sometimes freeze up on larger projects. On my first assignment, I lucked out and got a good grade...after asking my teacher about a dozen questions through email.

The fact that almost every seemingly useful tutorial or programming forum online is for C++ since apparently no one uses C anymore also puts a hamper on my ability to do research on my own. Is this normal for someone just getting into programming or should I be worried? Sort of feel like a moron compared to my peers. :/
 
How can I change a string to reflect new contents?

easier: change a pointer to point to the required string.


eg
Code:
#include <stdio.h>

void main()
{

    char name[50] = "You.";

    char* pointstowinner;

    pointstowinner = name;

    printf("A Winner is: %s", pointstowinner);


}


the longer explanation is that when you ask for winner_name to equal name, the program attempts to fill winner_name not with the contents of the name array, but with the address in memory where it is stored. This is a pointer to the first char (char*) and not an array of chars, which is why you get the error. From memory, when you ask printf to print out the contents of a memory address as a string it stops when it hits the first null character which is why you don't get "You.+lots of garbage" in the above code. There are also a bunch of functions in string.h like strcpy (copy), strcat (concatenate) for manipulating c-style strings, more reading here: http://en.wikipedia.org/wiki/C_string_handling
 

KorrZ

Member
I have a question about a something in C.

I'm doing an assignment and I wanted to make a string for someone's name.

Initialized it as

char name[50];

Now at the end of my function I want to make something called winner_name take on the value of whatever name is.

But when I try to do:

"winner_name = name;"

It tells me "incompatible types in assignment".

How can I change a string to reflect new contents?

You can't just assign a character array like that, use strcpy. In your case at the end of your function

strcpy(winner_name, name);

You need to include the string.h header to use it.
 
Taking a full time role with my present employer after working as a contractor for 2 years. Nice bump in pay, too (23%). Will also be nice to actually get some PTO.
 

Link1110

Member
I've been doing Harvard's CS50 on iTunesU, also available at http://cs50.tv/2011/fall/ I'd like to maybe do some iOS apps, so I'm happy to see an iOS course on that site as well (though I apparently need to buy a Mac, it was time to save up for a new computer anyway.)

Does anyone know if CS51 is available anywhere. I've been looking to no avail. No biggie, since only CS50 seems to be a prerequisite for the iOS programming course if I were to take it for credit anyway.
 

Newline

Member
Currently going into my 3rd year of a Computer Science degree and a week ago for my final year project I was tasked with creating a puzzle game for mobile phones.

When I heard this I was so happy, got well exited and started researching into the Android libraries for Java and began messing about.

This week I talked to my project supervisor and he told me I've gotta program it in J2ME. Flipping Heck. Just turned into the most mundane project ever, I feel like i've been restricted into a little box now. Here comes basic and generic puzzle game #121232302403.
 
The GAF programming challenge this week kind of forced me to learn recursive backtracking, which is one of many algorithms in said knowledge gaps.

Anyway, I guess what I'm asking is if anyone might have any suggestions of where I can start to become more well rounded. My experience consists of web apps, database interaction with .net, and various small scale c++, Java, and C# apps.

Good to hear that some of that stuff helped someone learn something. :) It is tough I think to get a good solid foundation in the concepts involved in programming. It's kind of a pain in the ass but I think that actually the best way to make sure you can plug those knowledge gaps is to get a couple of comprehensive books and just start plowing through them. Language specific stuff I would argue is less important, if you can program anything, you can learn the semantics and idioms of any new language, but it sounds like the core of algorithmic thinking is the most important thing for where you're at right now. I'm sure it's been recommended a hundred times in this thread but you could check out Introduction to Algorithms. I have a reference copy that I need to fall back on now and then and it really is astounding how much information is in this book. That might be a good place to start for just rounding off your knowledge.

There's a lot of information out there on the internets about programming but a lot of it is along the lines of "this is how you solve this one problem" rather than going into any great detail on the mental infrastructure you need to really grasp why that particular solution works well or is appropriate (or isn't, in a lot of cases). This is why some good books can be really really valuable.

Probably an idiotic and vague question but, how exactly do you study/practice programming? I'm currently taking a class in C, and while I can gather how to do simple things and how functions work, I feel overwhelmed and sometimes freeze up on larger projects. On my first assignment, I lucked out and got a good grade...after asking my teacher about a dozen questions through email.

The fact that almost every seemingly useful tutorial or programming forum online is for C++ since apparently no one uses C anymore also puts a hamper on my ability to do research on my own. Is this normal for someone just getting into programming or should I be worried? Sort of feel like a moron compared to my peers. :/

It's actually hard to get a good answer on this type of question from most programmers who have managed to get to the point where the ability to think logically through a problem and just understand how to implement it becomes second nature. It gets really difficult to remember what it was like starting out and how hard it was to just think of a way to solve a problem, never mind translating that into the correct syntax for the code. I can't claim to be that much more use to you, since I've been programming for too long now as well, but I do have more experience than most in dealing with people learning to code, since I teach and do lab supervision for 1st and 2nd years in my university at the moment. I see a lot of learners. :p

The thing that seperates the students who go on to do really well and the ones who don't isn't necessarily who gets the concepts the quickest or who is "naturally" good at it but it always seems to be the ones who just practice and practice and practice. And then when they've done that they practice some more. And then they mess up and do more practice. So the short answer is that no, you shouldn't feel like a moron, you're probably no worse off than most of them, but if you want to really improve and get better you need to do it over and over and over and over. Programming is a lot more like playing a musical instrument than people give it credit for, you need to do it a LOT to get good at it.

In terms of general advice, whenever you get a problem to solve you should always solve it on paper first. It might help to think of it in 3 stages:

1) Figure out the steps that you (meaning you, with the paper) have to do to solve the problem, and WRITE THEM ALL DOWN (I still do this sometimes, and it really helps)
2) Figure out what data you used (that is, which numbers, which words, which lists of things, whatever it is) and what you did to that data to solve the problem.
3) Translate the data and operations you did on that data to code, in small self contained chunks.

That might not help at all, but I've observed over and over again that new people have a really hard time just breaking a given problem down into small discrete steps that can be considered in isolation. Once you can reliably do that you'll find it gets easier to consider those operations as atomic, so that you can just read a problem and start turning it into code in your head instantly. That all takes a lot of practice though.

P.S. Did I mention you should practice?
 
I'm leading a large project at my company that needs to share a common codebase between a Java application and a C/C++ app. Those two techs aren't negotiable for various reasons. What I'd like to do is create a DLL and call into it natively on the C/C++ side and then JNI into it on the Java side.

A couple of concerns:
1. Can I marshal Java objects in the shared DLL if they're passed in by JNI? Even call member functions of the object?

2. Is there a better approach to this than using JNI? Should I script the common functionality using something like Lua or Perl? It still presents problems for me marshaling objects from both sides, I would think.

I want a common codebase because I don't want to repeat the business rules on both sides of the divide. There should be a single, safe source for such things.
 

Korosenai

Member
Hello everyone, ive got a question concerning a computer science degree.

I'm about to start on a degree called Information and Computer Science (ICS). What is the difference between ICS and CS?

For reference, I'll be taking classes such as Web programming, computer networking, calculus, and analytic geometry.
 

Kalnos

Banned
I'm about to start on a degree called Information and Computer Science (ICS). What is the difference between ICS and CS?

For reference, I'll be taking classes such as Web programming, computer networking, calculus, and analytic geometry.

What school is it a part of? Engineering, business, arts/sciences?
 

Zoe

Member
Hello everyone, ive got a question concerning a computer science degree.

I'm about to start on a degree called Information and Computer Science (ICS). What is the difference between ICS and CS?

For reference, I'll be taking classes such as Web programming, computer networking, calculus, and analytic geometry.

Web programming + networking tells me you'll be learning more practical versus theoretical.
 
Currently going into my 3rd year of a Computer Science degree and a week ago for my final year project I was tasked with creating a puzzle game for mobile phones.

When I heard this I was so happy, got well exited and started researching into the Android libraries for Java and began messing about.

This week I talked to my project supervisor and he told me I've gotta program it in J2ME. Flipping Heck. Just turned into the most mundane project ever, I feel like i've been restricted into a little box now. Here comes basic and generic puzzle game #121232302403.

I feel sorry for you. J2ME sucks ass, I had to use it last semester for a project I did and I hated it. Here's a tip, don't use Eclipse Pulsar if possible. NetBeans is much better for that task. J2ME is also based on an old-ass Java version. I think it uses part of the JRE 1.3 libraries, so: no enums, no generics, no Java Collections Framework (you have a Vector class which works similarly to an ArrayList). It just feels really limited. The good part is that there is an okay-ish game programming framework that is included in the libraries. (Sprite/Tile based stuff)
 

hitsugi

Member
Just curious, but surely some of you use a Linux distro.. and for those of you that do:

Is there any you know of that easily support different styles like Visual Studio does? I prefer darker backgrounds with light fonts; seems to just be easier on my eyes. I've tried Eclipse and CodeBlocks and neither seemed to have an easy option for what I'm looking for.
 
Hey Gaf, is the any way to use getch() in C on a Mac? I have tried it and I am told by the terminal that it isn't in the library. I tried invoking it with "gcc -lcurses" and conio.h, including the necessary .h references in the .c file, and nothing works. I searched around online, but it looks like everything relating to getch() talks about MS-DOS. And, it needs to be getch(), not getchar() or any other method. I suppose I can just compile and run the program in Windows if need be, but I was just wondering if it is possible in the Mac.
 

VanillaPMP

Neo Member
Just curious, but surely some of you use a Linux distro.. and for those of you that do:

Is there any you know of that easily support different styles like Visual Studio does? I prefer darker backgrounds with light fonts; seems to just be easier on my eyes. I've tried Eclipse and CodeBlocks and neither seemed to have an easy option for what I'm looking for.

It is a crime to code in Linux using anything other than VIM or Emacs, bah ram ewe!

But seriously, I just use text editors when I am working in linux, and they all have some sort of functionality for changing color schemes. A quick google search found this for eclipse http://eclipsecolorthemes.org/ which may help you configure the IDE to your liking.
 

Bollocks

Member
Hey Gaf, is the any way to use getch() in C on a Mac? I have tried it and I am told by the terminal that it isn't in the library. I tried invoking it with "gcc -lcurses" and conio.h, including the necessary .h references in the .c file, and nothing works. I searched around online, but it looks like everything relating to getch() talks about MS-DOS. And, it needs to be getch(), not getchar() or any other method. I suppose I can just compile and run the program in Windows if need be, but I was just wondering if it is possible in the Mac.

Not possible, if it really needs to be getch() as you've said then you have to use windows.
e: I take this is an assignment, you could theoretically also write your own getch() function and use compiler directives so that when you compile it under windows it automatically uses the native function. Might get you some plus points :D
 

hitsugi

Member
It is a crime to code in Linux using anything other than VIM or Emacs, bah ram ewe!

But seriously, I just use text editors when I am working in linux, and they all have some sort of functionality for changing color schemes. A quick google search found this for eclipse http://eclipsecolorthemes.org/ which may help you configure the IDE to your liking.

I can't tell you how much time I feel I wasted trying to learn VIM when what I really needed to be learning was C++ for my intermediate comp sci class.....

thanks for the link. I hear EclipseCDT is pretty solid for C++
 
The only legit C++ IDE I've found on linux (having tried pretty much all of them) is QtCreator.

codeblocks is okay in small doses, but the gdb wrapper is garbage and it's extremely glitchy. Eclipse is slow and clunky and I hate using it.

vi is alright for cases where I don't have a mouse.
 

usea

Member
I often see people praising vim and emacs and there are about a million guides on how to make the best of them. In the spirit of that, here are some of the things I've figured out about quickly editing text in windows. Most of these work in visual studio, notepad++, netbeans, eclipse, code blocks, etc etc. Anything to keep from touching the mouse, which is a huge productivity-killer.

Obviously, there are the basics. I'm sure you know these, but it's better to be thorough:
Code:
&#8226; ctrl-x  -  cut
&#8226; ctrl-c  -  copy
&#8226; ctrl-v  -  paste
&#8226; ctrl-z  -  undo
&#8226; ctrl-y  -  redo (un-undo)
&#8226; home  -  go to the beginning of the line
&#8226; end  -  go to the end of the line
&#8226; backspace  -  delete to the left of the cursor
&#8226; delete  -  delete to the right of the cursor.
&#8226; shift+arrow keys  -  highlight/select text
&#8226; ctrl-a  -  highlight all text

Some lesser known ones:
Code:
&#8226; ctrl-left/right arrow keys  -  move the cursor one word at a time. Usually this goes by spaces, but depending on the context it might stop at other characters too. Super useful.
&#8226; ctrl-shift-left/right arrow keys  -  select one word at a time.
&#8226; ctrl-backspace  -  backspace one word
&#8226; ctrl-delete  -  delete one word
&#8226; ctrl-home  -  go to the very top of the document
&#8226; ctrl-end  -  go to the very bottom of the document
&#8226; shift-home  -  select text from the cursor to the beginning of the line
&#8226; shift-end  -  select text from the cursor to the end of the line
&#8226; alt-shift-up/down arrows  -  makes the cursor span multiple lines. This way you can type, select, etc on multiple lines at once. Try it to see what I mean.
&#8226; ctrl-L  -  cut the entire current line

I guarantee that whichever editor you use has plenty more that are very useful, but probably specific to that environment. Visual studio lets you select the current word with ctrl-w, netbeans lets you move the current line up or down with alt-shift-up/down. Etc etc.
 
Not possible, if it really needs to be getch() as you've said then you have to use windows.
e: I take this is an assignment, you could theoretically also write your own getch() function and use compiler directives so that when you compile it under windows it automatically uses the native function. Might get you some plus points :D
That is what I thought. Thank you for the confirmation. I guess I will try to use GNU C compiler on Windows tomorrow. At least I can do blind programming on the Mac and not have to use the Windows machine that often.
 

Kalnos

Banned
I guarantee that whichever editor you use has plenty more that are very useful, but probably specific to that environment. Visual studio lets you select the current word with ctrl-w, netbeans lets you move the current line up or down with alt-shift-up/down. Etc etc.

Another cool one in VS is being able to highlight lines and hit 'tab' to space them all and being able to 'shift-tab' to move them backwards.
 

usea

Member
Another cool one in VS is being able to highlight lines and hit 'tab' to space them all and being able to 'shift-tab' to move them backwards.
Yep! I would die without this feature. I use it constantly. Fortunately pretty much every editor I've used has it.
 

hateradio

The Most Dangerous Yes Man
The best text editor I've used is Notepad++.

It lets you cut out entire lines, cut them, duplicate them, tab them, untab them, comment them, etc. It also lets you hide all code by fold level.

Code:
level 1 {
  level 2 {
    level 3 {
    }
    level 3 {
      level 4 {
      }
    }
  }
}

Netbeans is nice, but I dislike that it doesn't always show collapsing markers and that you can only collapse the first level.
 

Pirabear

Banned
It's actually hard to get a good answer on this type of question from most programmers who have managed to get to the point where the ability to think logically through a problem and just understand how to implement it becomes second nature. It gets really difficult to remember what it was like starting out and how hard it was to just think of a way to solve a problem, never mind translating that into the correct syntax for the code. I can't claim to be that much more use to you, since I've been programming for too long now as well, but I do have more experience than most in dealing with people learning to code, since I teach and do lab supervision for 1st and 2nd years in my university at the moment. I see a lot of learners. :p

The thing that seperates the students who go on to do really well and the ones who don't isn't necessarily who gets the concepts the quickest or who is "naturally" good at it but it always seems to be the ones who just practice and practice and practice. And then when they've done that they practice some more. And then they mess up and do more practice. So the short answer is that no, you shouldn't feel like a moron, you're probably no worse off than most of them, but if you want to really improve and get better you need to do it over and over and over and over. Programming is a lot more like playing a musical instrument than people give it credit for, you need to do it a LOT to get good at it.

In terms of general advice, whenever you get a problem to solve you should always solve it on paper first. It might help to think of it in 3 stages:

1) Figure out the steps that you (meaning you, with the paper) have to do to solve the problem, and WRITE THEM ALL DOWN (I still do this sometimes, and it really helps)
2) Figure out what data you used (that is, which numbers, which words, which lists of things, whatever it is) and what you did to that data to solve the problem.
3) Translate the data and operations you did on that data to code, in small self contained chunks.

That might not help at all, but I've observed over and over again that new people have a really hard time just breaking a given problem down into small discrete steps that can be considered in isolation. Once you can reliably do that you'll find it gets easier to consider those operations as atomic, so that you can just read a problem and start turning it into code in your head instantly. That all takes a lot of practice though.

P.S. Did I mention you should practice?

Thanks for the post. You're absolutely correct in thinking the main problem is that I look at things through the bigger picture rather than just breaking things down into smaller pieces. On my latest Assignment I tried tackling it piece-by-piece and everything went really smoothly.

And yeah, I've been practicing (although admittedly way more in the past 2 weeks than I have previously).
 

ferr

Member
I'm trying to get a C# WinForm to send keyboard inputs to another form (VisualBoyAdvance in this case). I'm using some p/invoke to do this (FindWindowByCaption, keybd_event, SetForegroundWindow) and these methods work great when targetting Notepad, but nothing at all seems to happen when targetting VBA.

The only thing I've seen happen, after trying to send over input, if I open up a joypad config window, it spams NUMLOCK in each entry.. kind of odd. That at least tells me that it's finding the window correctly.. but maybe it can't send input to it?

Anyone played with something like this before? I sure would like to play some roms on my iPad via splashtop with touch controls :(
 

mike23

Member
I'm trying to get a C# WinForm to send keyboard inputs to another form (VisualBoyAdvance in this case). I'm using some p/invoke to do this (FindWindowByCaption, keybd_event, SetForegroundWindow) and these methods work great when targetting Notepad, but nothing at all seems to happen when targetting VBA.

The only thing I've seen happen, after trying to send over input, if I open up a joypad config window, it spams NUMLOCK in each entry.. kind of odd. That at least tells me that it's finding the window correctly.. but maybe it can't send input to it?

Anyone played with something like this before? I sure would like to play some roms on my iPad via splashtop with touch controls :(

Check this out

http://inputsimulator.codeplex.com/
 

amrihua

Member

just another reason to avoid C++


What are some good beginner level books for php, ruby, perl, and javascript?

start with a free online tutorial


I have a question about a something in C.

I'm doing an assignment and I wanted to make a string for someone's name.

Initialized it as

char name[50];

Now at the end of my function I want to make something called winner_name take on the value of whatever name is.

But when I try to do:

"winner_name = name;"

It tells me "incompatible types in assignment".

How can I change a string to reflect new contents?

Strings are arrays of characters, arrays and pointers are two ways to represnt the same thing, so strings can be manipulated using pointers. Just make winner_name point to the address of name (no copying is done).

Code:
char name[50];

char *winner_name;

winner_name = name;

There are other ways too using pointers. Look them up and learn them. C is all about pointers.

Strings are null terminated in C, so you can easily (3 lines) make a while loop that copies element by element from name to winner_name.

PS: strcpy() is like 4 or 5 lines and very trivial.
 

tirant

Member
Just curious, but surely some of you use a Linux distro.. and for those of you that do:

Is there any you know of that easily support different styles like Visual Studio does? I prefer darker backgrounds with light fonts; seems to just be easier on my eyes. I've tried Eclipse and CodeBlocks and neither seemed to have an easy option for what I'm looking for.

Geany.

The best text editor I've used is Notepad++.

It lets you cut out entire lines, cut them, duplicate them, tab them, untab them, comment them, etc. It also lets you hide all code by fold level.

That's been available for ages in vim ;)
 
One npp feature that blew my mind:
Ksu3e.png


It also lets you type on multiple rows simultaneously. I end up using it more than expected.
 

RJT

Member
Hey guys,

I was wondering what is your opinion on Google App Engine?

I'm a noob when it comes to programming and I'm not really interested in coding professionally, but I've been taking some online courses as a hobby. Udacity has a great course on web programming that uses GAE, and I've been building a simple platform to build political movements (sort of a bastard child of Political Parties, Wikipedia and Reddit). It's just so easy to use GAE that I can't help but think that there is something wrong with it.

Anyways, anyone has some experience with it? What do ya'll think?
 

Bentles

Member
Hey guys. I'm working on a project in VS and I've got some code I'm scared to change! At least not without a convenient way to go back to how it is now. Is there some sort of version control software or something I should be using? Is "AnkhSVN" what I'm looking for? I'm pretty out of my depth with this.
 

Bentles

Member
Hey guys. I'm working on a project in VS and I've got some code I'm scared to change! At least not without a convenient way to go back to how it is now. Is there some sort of version control software or something I should be using? Is "AnkhSVN" what I'm looking for? I'm pretty out of my depth with this.

No need. My friend set me up with something.
 

BHZ Mayor

Member
Anyone with any web programming experience? I'm thinking about getting into WebMatrix or Visual Web Developer to freelance, but there's one thing I can't figure out. If someone is paying up front or by the hour, I'm pretty sure they will want to see some progress on development of the site, so how would I be able to show that to someone on another PC (that doesn't have the development tools) without actually publishing it?
 

Zoe

Member
Anyone with any web programming experience? I'm thinking about getting into WebMatrix or Visual Web Developer to freelance, but there's one thing I can't figure out. If someone is paying up front or by the hour, I'm pretty sure they will want to see some progress on development of the site, so how would I be able to show that to someone on another PC (that doesn't have the development tools) without actually publishing it?

You really should publish it. Otherwise it's as good as screen shots.
 

Kinitari

Black Canada Mafia
Wondering if anyone can help me out here - working on an ASP.NET site in visual studios, and I want to share what I've done so far with my (terrible, terrible) group mates. They did not understand the concept of a svn, let alone how to set one up on their machines - so I couldn't exactly share my work that way.

Unfortunately, I can't for the life of me figure out a clean and easy way to package my work into a zip and email it to them, my sln is down one path, and my website content is down another - if I copied them both, shoved them in the same folder and sent it away, the person opening it would get a pathing error.

Any help?

edit: nm, think I got it - was working with the precompiled version.
 
Damn I really need help, i've been searching for hours. I'm using C++ and I am trying to read a text file, and store only certain values from that text file into an array so that I can later use them as data values for a polygon.


here's what I have. Something isn't working with the getline() function.
Code:
#include <stdio.h>;
#include <stdlib.h>;
#include <GL/glut.h>;
#include <iostream>;
#include <sstream>;
#include <fstream>;
#include <string>;
void readFile()
{

	string line;
	short loop = 0;
	int temp[100];	//where i store my data from text file
	int vertex;		//data from text file

	ifstream infile;
    infile.open("polygon.txt");

    // Exit if file opening failed
    if (!infile.is_open()){
        cerr<<"Failed to open file" <<endl;
        exit(1);
    }

    // Start reading data
    while (!infile.eof()){
		for (int i = 0; i<100; i++)
			{
				vertex = infile.getline();
				temp[i] = vertex;
		}
            
    }

    infile.close();
}
 
Top Bottom