View Full Version : learning C
phacemeltar
01-31-2014, 06:30 PM
hi all, i am having some trouble learning c. its for this class i am taking outside of school, and i want to do well. what i am having trouble with is figuring out how the syntax works.
is there anyone willing to help me learn some rudimentary principles? here (http://cdn.cs50.net/2014/x/psets/1/pset1/pset1.html) is a link to the problem set. i am having trouble with the mario problem.
can someone please explain how to put the blank spaces in, and also how to make new lines?
quido
01-31-2014, 06:36 PM
Read about whitespace and escape sequences in C =P
baalzy
01-31-2014, 07:41 PM
http://www.learn-c.org/
Learn C#, download eqbrowser source, pras.
Learn C++, download Eqemu source, pras
stormlord
01-31-2014, 07:45 PM
If I recall, it's something like cout << "       ##";
The ASCI for a space is 32 (decimal) I think.
Or is that c++?
I started with c or c++ in school, I forget. I used Turbo C++.
As far as the code is concerned, it looks simple to me. Each row above the bottom has (0+row) spaces. It looks like hte platform at the top is 2 characters in length. The width of the total pyramid can be estimated by (height+1). The number of blocks per row can be estimated by (width of the pyramid-spaces).
EDIT: I forgot about the role of printf in C.
You will probably want to loop printf(" "); to insert spaces on the line.
Insert pound signs the same way by looping printf("#"); and ending with printf("\n");
Honestly you just need to experiment with it.
quido
01-31-2014, 07:52 PM
Borland Turbo C++ lol - I used to use that.
He's probably expected to use printf/scanf, not cout/cin and the stream operators as they are from C++.
stormlord
01-31-2014, 08:19 PM
Borland Turbo C++ lol - I used to use that.
He's probably expected to use printf/scanf, not cout/cin and the stream operators as they are from C++.
Ya when I made the initial post I forgot about.
What do you do with programming? I use it as a hobby. I took classes in colllege. My first exposure to it was when I was a sophmore in HS. I was using Qbasic. It's an easy language to start out.
Alwys interested to hear from other programmer.
phacemeltar
01-31-2014, 08:20 PM
http://www.learn-c.org/
genius! im working on this now.
thanks to everyone else for all the answers. this assignment isnt due for awhile, but im falling behind in my group due to my confusion. 
mainly im having a hard time figuring out how to write one algorithm that will print multiple lines based on user-input. 
ill read through these responses and hopefully i can come up with something.
quido
01-31-2014, 08:27 PM
you should learn about variables, and then loops =) these are essential for solving this problem
baalzy
01-31-2014, 08:27 PM
Its been forever since I've done anything with C and I always hated it, so I never got into making elegant solutions.  For something suitable you can use these concepts to solve this and then I'll provide some really weakass pseudo-code for you:
Concepts: 
http://www.learn-c.org/en/Arrays
http://www.learn-c.org/en/Strings
http://www.learn-c.org/en/For_loops
http://www.learn-c.org/en/While_loops
(If you don't know about Variables and If-Else statements you should read up on them also).
Weakass pseudo-code for the printing of valid input only, stored in a variable called N:
Create Char array.
print the text "Height: " with the value from N appended after the space.
Use a forloop.  Your goal here is to Print a line at the end of each cycle until you have printed N lines.
Using a while loop here (inside the forloop), your goal is to fill in the appropriate number of Blank spaces in your array and then the appropriate number of hashes.  Think about what you can do with an Array and a While loop to accomplish this goal.
Hint: If this is the first time the Forloop has ran, you'll want to print N-2 spaces followed by two hashes.
After the while loop is finished, before the end of the forloop.  Print the array.
Edit: After thinking about this a bit more it's possible to do this without an array too, and might be easier for you.
phacemeltar
01-31-2014, 08:28 PM
you should learn about variables, and then loops =) these are essential for solving this problem
roger
Sarajo
02-02-2014, 02:00 PM
And keep it modular! But I suck at explaining that.
I'm learning C# for a class right now. Working toward a CS/information science degree.
The first rule of C#: When you google it, it's "C sharp".
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.