What do you mean by suceeding?
I asked around on another forum and they told me I had to use function() instead of function(void)
[QUOTE=MountainWatcher;33557227]What do you mean by suceeding?[/QUOTE]
Google 'scanf'.
Read the section titled 'return value'.
Well, I think I get it, but when it says I'm ignoring it, what does it mean? How do I verify that scanf returned all of the values I want it to be?
Or when the website says function, it means the actual int x(void) function and the number of values on the return command? And if so, shouldn't that warning pop lots of times for the main function that doesn't return anything?
What? No.
Strictly speaking, your compiler doesn't even have to warn you about that. GCC just knows that you have no idea WTF you're doing and is offering some help.
Functions only 'return' one value. The arguments you pass to scanf() are not referred to as 'return values', even though they're modified by scanf() to pass information back to your program. You obtain the return value from the function by writing "x = foo(/*args go here*/)".
In this case, you want:
[cpp]
int err = scanf(/* args go here */);
if (err != /* however many values you expected scanf to parse */) {
/* scanf failed somehow, handle the error */
return some_error_code;
}
/* proceed with processing */
[/cpp]
You guys are suepr helpful but I'm still confus.
Just curious, but is this like a serious CS/EE course, or is this like 'C programming for mechanical engineers', where everyone's just going to forget it anyway?
It seems like you should have some kind of grasp about how functions work this late in the semester.
TBQH, I think every course that's going to introduce students to C or C++ should start off with binary two's-compliment arithmetic and pen-and-paper stack machines, moving onto stack frames, function invocation, memory and pointers, before ever having students write a line of code. You really can't function in a low-level language without these solid foundations. Introducing these ideas at the beginning would save students so much confusion in the long run.
Or just teach students a language which doesn't force you to work so close to the metal so that they can focus on the problem-solving process...
Mechanical.
[editline]4th December 2011[/editline]
well, "Programming 1" It's for physicists.
[editline]4th December 2011[/editline]
But don't physicists really need programming? To help with calculations, models, predictions and whatnot.
Programming is always useful, and C is probably the most ubiquitous language there is, but for someone who's [i]specifically[/i] interested in numerical calculations and modelling, MATLAB is probably the most practical option.
Although, some of the greatest programmers (including C programmers) are physicists. RMS (insane software hippy) and Dennis Ritchie (the dude who created C) were both physicists, a few of my Comp. Eng. professors were physicists. The guy who writes [url=http://xkcd.com/]xkcd[/url] is a physicist.
So, I dunno. It's certainly useful and a lot of physicists probably pick it up for a reason.
Well, I sure as fuck am neither.
Why does my program jam when I pick an option? The window doesn't close, it doesn't let me type new numbers, nothing is printed, jack shit. And that option should be included in a while cycle that depends o n a variable that the option i'm speaking of doesn't even have in its body.
Seriously, I have 4 days or so to get this program in for grading and I spent like 3 days on the menu :v:
I started learning DirectX from [url]http://www.directxtutorial.com/[/url] but I reached the end of the free tutorial. I didn't really get too much out of it though. Where should I go next in continuing my education? Preferably for free.
[QUOTE=Agent766;33560496]I started learning DirectX from [URL]http://www.directxtutorial.com/[/URL] but I reached the end of the free tutorial. I didn't really get too much out of it though. Where should I go next in continuing my education? Preferably for free.[/QUOTE]
I'd stick with the sdk and msdn.
[url]http://msdn.microsoft.com/en-us/library/windows/desktop/ee663274%28v=VS.85%29.aspx[/url]
The sdk has loads of samples and tutorials for 9, 10 and 11, and msdn will be able to tell you everything else you need to know. Also if you're looking for 9 or 10 they're under classic directx graphics.
Say I have a text box with strings being added to it regularly on new lines like this.
Greg
Bob
Mary
Then I want to take out one name and replace it with nothing.
textBox1.Text.Replace("Bob", string.Empty);
Ends up like this.
Greg
Mary
Any way I could remove the gap?
[QUOTE=reevezy67;33561846]Say I have a text box with strings being added to it regularly on new lines like this.
Greg
Bob
Mary
Then I want to take out one name and replace it with nothing.
textBox1.Text.Replace("Bob[b]\n[/b]", string.Empty);
Ends up like this.
Greg
Mary
Any way I could remove the gap?[/QUOTE]
You'd need to remove the newline character too.
Assuming you're always using AppendLine or .Text += "whatever\n" or SOMETHING like that (so that you'll always have a new line after the word), instead of using replace("Bob".. use Replace("Bob\n", ..
I was using Enviroment.Newline;
now that I try to use \n it wont work for some reason, it doesn't put in the new line.
textBox5.Text += a + "\n";
a being a string.
If you're on Windows, it's "\r\n"
[QUOTE=robmaister12;33561996]If you're on Windows, it's "\r\n"[/QUOTE]
Thanks, I've always just used Enviroment.Newline so I have never known that.
Environment.Newline is the preferred method according to C# documentation, as Mono will change it to \n under Linux and OS X. But "Environment.Newline" is much longer than "\n" and most of the time you'll be writing both the serializer and the deserializer and will stick to only one format between every OS, so it really doesn't matter.
Does the OpenGL Superbible have a lot of tutorials or does it assume you already know a bit about OpenGL?
It takes you through everything from the basics, and it comes with a bunch of source code and tutorials for all of the articles in the book on both windows and linux (not sure about mac but probably it too).
I haven't used it myself but one of my friends thinks it's pretty good.
OpenGL Superbible 5th edition is pretty good, it eases you into non-deprecated OpenGL. I used it when I was trying to learn non-deprecated OpenGL (although I had prior OpenGL experience so I could very quickly skim the first few chapters), and I still look at it sometimes to learn about something I haven't worked with.
Also having a full printed copy of the OpenGL reference pages is pretty cool, but I find it mostly useless since I have a good internet connection most of the time.
Is adding images to a rich text box possible?
Guys, can I make an array with number of elements defined by user with Pascal?
I'm trying to create a method that can test whether or not a number is prime:
[CODE]
public static bool isPrime(int number)
{
for (int factor = 2; factor < number; factor++)
{
if (number % factor == 0)
{
Console.WriteLine(factor);
return false;
}
else
{
number++;
}
}
return true;
}
[/CODE]
The number 7 returns as false, when it should be true and the factor this event occurs with is 5.
[csharp]
try
{
label1.Text = "Status: Preparing";
textBox1.ReadOnly = true;
saveFileDialog1.ShowDialog();
FileInfo fi = new FileInfo(saveFileDialog1.FileName);
string destination = fi.DirectoryName;
string filename = fi.Name;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ur);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(textBox2.Text, textBox3.Text);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
label1.Text = "Status: Downloading";
Stream stream;
StreamReader reader;
StreamWriter writer;
stream = request.GetRequestStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(destination + @"/" + filename, false);
writer.Write(reader.ReadToEnd());
label1.Text = "Status: Completed";
}
catch (Exception ex)
{
Console.WriteLine(ex);
label1.Text = "Status: Error";
}
[/csharp]
Exception
System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
at System.Net.FtpWebRequest.GetRequestStream()
at Client2.Form3.Download(Uri ur) in C:\Users\Evan\Documents\Visual Studio 2010\Projects\Client2\Client2\Form3.cs:line 227
Kind of lost..
Is it something to do with request.Method being DownloadFile?
Fixed with
[csharp]
stream = request.GetResponse().GetResponseStream();
[/csharp]
[QUOTE=joyenusi;33565824]I'm trying to create a method that can test whether or not a number is prime:
[CODE]
public static bool isPrime(int number)
{
for (int factor = 2; factor < number; factor++)
{
if (number % factor == 0)
{
Console.WriteLine(factor);
return false;
}
else
{
number++;
}
}
return true;
}
[/CODE]
The number 7 returns as false, when it should be true and the factor this event occurs with is 5.[/QUOTE]
This part fucks it up:
[code]else
{
number++;
}[/code]
Remove it and it works.
[QUOTE=ZeekyHBomb;33550706]Try setting a breakpoint at exit and _exit (b exit and b _exit). When it halts, do bt to see the call stack.
I'll be good to have a debug-build so the call stack is completely in tact.[/QUOTE]
[code]Reading symbols from /home/richy/codeblocks/anoy/bin/Debug/anoy...done.
(gdb) b exit
Function "exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (exit) pending.
(gdb) b _exit
Function "_exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (_exit) pending.
(gdb) b exit()
Function "exit()" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 3 (exit()) pending.
(gdb) run
Starting program: /home/richy/codeblocks/anoy/bin/Debug/anoy
[Thread debugging using libthread_db enabled]
Breakpoint 1, __GI_exit (status=1) at exit.c:99
99 exit.c: No such file or directory.
in exit.c
(gdb) bt
#0 __GI_exit (status=1) at exit.c:99
#1 0x00855697 in _intel_batchbuffer_flush ()
from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#2 0x008594f0 in intel_flush () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#3 0x00859532 in ?? () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#4 0x009354b0 in _mesa_flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#5 0x00935bce in _mesa_Flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#6 0x00167ac1 in sf::priv::RenderTextureImplFBO::UpdateTexture (
this=0x8b5cc50)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTextureImplFBO.cpp:140
#7 0x001670e0 in sf::RenderTexture::Display (this=0xbfffdb00)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTexture.cpp:115
#8 0x080494e0 in main () at /home/richy/codeblocks/anoy/main.cpp:40
(gdb)
[/code]
[QUOTE=reevezy67;33565834][csharp]
try
{
label1.Text = "Status: Preparing";
textBox1.ReadOnly = true;
saveFileDialog1.ShowDialog();
FileInfo fi = new FileInfo(saveFileDialog1.FileName);
string destination = fi.DirectoryName;
string filename = fi.Name;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ur);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(textBox2.Text, textBox3.Text);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
label1.Text = "Status: Downloading";
Stream stream;
StreamReader reader;
StreamWriter writer;
stream = request.GetRequestStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(destination + @"/" + filename, false);
writer.Write(reader.ReadToEnd());
label1.Text = "Status: Completed";
}
catch (Exception ex)
{
Console.WriteLine(ex);
label1.Text = "Status: Error";
}
[/csharp]
Exception
System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
at System.Net.FtpWebRequest.GetRequestStream()
at Client2.Form3.Download(Uri ur) in C:\Users\Evan\Documents\Visual Studio 2010\Projects\Client2\Client2\Form3.cs:line 227
Kind of lost..
Is it something to do with request.Method being DownloadFile?[/QUOTE]
stream = request.GetRequestStream();
should be
stream = response.GetResponseStream();
[url]http://stackoverflow.com/questions/3981564/cannot-send-a-content-body-with-this-verb-type[/url]
[QUOTE=Richy19;33565914][code]Reading symbols from /home/richy/codeblocks/anoy/bin/Debug/anoy...done.
(gdb) b exit
Function "exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (exit) pending.
(gdb) b _exit
Function "_exit" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (_exit) pending.
(gdb) b exit()
Function "exit()" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 3 (exit()) pending.
(gdb) run
Starting program: /home/richy/codeblocks/anoy/bin/Debug/anoy
[Thread debugging using libthread_db enabled]
Breakpoint 1, __GI_exit (status=1) at exit.c:99
99 exit.c: No such file or directory.
in exit.c
(gdb) bt
#0 __GI_exit (status=1) at exit.c:99
#1 0x00855697 in _intel_batchbuffer_flush ()
from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#2 0x008594f0 in intel_flush () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#3 0x00859532 in ?? () from /usr/lib/i386-linux-gnu/dri/i965_dri.so
#4 0x009354b0 in _mesa_flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#5 0x00935bce in _mesa_Flush () from /usr/lib/i386-linux-gnu/dri/libdricore.so
#6 0x00167ac1 in sf::priv::RenderTextureImplFBO::UpdateTexture (
this=0x8b5cc50)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTextureImplFBO.cpp:140
#7 0x001670e0 in sf::RenderTexture::Display (this=0xbfffdb00)
at /home/richy/Desktop/LaurentGomila-SFML-09854ba/src/SFML/Graphics/RenderTexture.cpp:115
#8 0x080494e0 in main () at /home/richy/codeblocks/anoy/main.cpp:40
(gdb)
[/code][/QUOTE]
You'll probably have to bug the SFML dev about that.
Could also be a driver problem though.
[QUOTE=joyenusi;33565824]I'm trying to create a method that can test whether or not a number is prime:
[CODE]
public static bool isPrime(int number)
{
for (int factor = 2; factor < number; factor++)
{
if (number % factor == 0)
{
Console.WriteLine(factor);
return false;
}
else
{
number++;
}
}
return true;
}
[/CODE]
The number 7 returns as false, when it should be true and the factor this event occurs with is 5.[/QUOTE]
You're incrementing 'number'.
Your routine is doing this:
[code]
Number Factor
7 2
8 3
9 4
10 5
[/code]
Also, you don't need to test [i]every [/i]number. You only need to test values up to sqrt(number), and only primes, as any non-prime number can be factored into primes.
If you wanted this to go really fast, what I'd do is I'd store a lookup table of the first [i]x [/i]prime numbers. The value of [i]x [/i]would depend on the largest prime you want to be able to check for. If you want to be able to check 2^n values, then you need primes up to 2^n/2. For example, if you want to be able to check [i]any [/i] 32-bit integer, then you'd need a table of primes up to 2^16. 65,537 is the 6,543rd prime which means your LUT needs 6,543 entries, a 6.4kB lookup table. Your routine to check the values would then be:
[code]
bool isprime(int number) {
int maxfactor = sqrt(number)
for (int i=0; i < num_primes; i++) {
int prime = primes[i];
if (prime > maxfactor) break;
if (number % prime == 0) return false;
}
return true;
}
[/code]
If you were to test a large number, say four billion, your method would iterate through all four billion values, whereas this LUT method will only check ~6,500.
For some reason, the parent constructor of a derived class I wrote isn't executing
[code]
Guest::Guest()
: Member("Guest", "Guest")
{
}
[/code]
I stepped through it and found that it the derived class constructor above does actually execute, but the parent constructor does not.
[editline]5th December 2011[/editline]
nevermind, had something to do with pointers
Sorry, you need to Log In to post a reply to this thread.