This is an archive of a previous version of Sodarace.

Please visit http://sodarace.net for the latest version.

forum  |  »» sodaplay
 
»» forums  »» community discussion forum

subject: Do you want to learn to program in C

357 replies on 24 pages. most recent reply: Tues, Aug 28 10:58 PM by matthew102000

»» back to topic list  

This topic has 357 replies on 24 pages [ « | 1 ... 5 6 7 8 9 10 11 12 13 ... 24  | » ]
»» previous topic   »» next topic  


cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 26-Mar-07 22:57   »» 
It needs to be %s, not %c

#include <stdio.h>

int main (void)

{
char fname[50], type[5000];
FILE *fp;

printf("FILE GENERATOR\n");
printf("-----------------------------------------\n");
printf("Name of file\n \n \t - ");
scanf("%s", fname);


printf("What do you want it to say?\n \n");
scanf("%s", type);


fp = fopen( fname, "w");
fprintf( fp,"%s", type);
fclose(fp);



scanf("%c");

return 0;

}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 26-Mar-07 23:12   »» 
now it only works with one word. now whats the problem???

and is there any way that i could only allow a certain amount of words on one line???

matt wuz here

ssuden_deth

»» models

Re: Do you want to learn to program in C   posted: 27-Mar-07 07:19   »» 
I think the problem is Here:


printf("FILE GENERATOR\n");
printf("-----------------------------------------\n");
printf("Name of file\n \n \t - ");
scanf("%s", fname);


that is all I can tell you

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 27-Mar-07 19:25   »» 
I plan to cover arrays, pointers, memory allocation, making your own functions, global varaibles and scope, structures, reading from files possibly, compiling with multiple source files, casting and now that you mentioned it I will cover the switch statement. I dont know if ill cover directives, i may if i feel it will be useful. I have started on it but it is coming along kinda slow. I have been very very busy. When i do get it done, i will not be able to post till the beginning of next week when i have access a internet connection faster than 28.8

Matthew, you said it only works with one word. Do you mean it only gets one word you typed and puts it in the file. scanf() will only get the first word. Try the function gets(), to get the ALL the text into type[] put

gets(type);

and it will get all the text from the user.

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 27-Mar-07 20:47   »» 
How do you make it so that the user chooses a setting? I mean that I have an idea for how to make a calaulator:)

~mmaarrkkuuss~

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 27-Mar-07 20:48   »» 
STDP I forgot to say please;D

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 27-Mar-07 23:11   »» 
you could do a thing like this:


#include <stdio.h>

int main (void)

{
char choice

printf("Chose a number:/n");
printf("1 = choice 1/n");
printf("2 = choice 2/n");
printf("3 = choice 3/n");
scanf("%c", choice);

if (choice=1)
{
do something;
};
else
{
if (choice=2)
{
do something else;
};
else
{
if (choice=3)
{
do something else again;
};
};
};
};

or somethin like that...
I'm a little rusty on my C syntax, I'm more used to C++ :P

Hope that helps, and that dp was very polite of you!

~~~[ROBO]>={he who hates C#}~~~

cactus2

»» models

Re: Do you want to learn to program in C   posted: 27-Mar-07 23:25   »» 
#include <stdio.h>

int main (void)

{
char choice;

printf("Chose a number:/n");
printf("1 = choice 1/n");
printf("2 = choice 2/n");
printf("3 = choice 3/n");
scanf("%c", choice);

switch(choice)
{
case '1':
Do something;
break;
case '2':
Do something;
break;
case '3':
Do something;
break;
}
}
}

cactus2

»» models

Re: Do you want to learn to program in C   posted: 27-Mar-07 23:27   »» 
STDP

In case you were wondering, I didn't get hacked. I just forgot my password and have both my accounts set to the same e-mail address. Man I'm dumb..

cactus2

»» models

Re: Do you want to learn to program in C   posted: 28-Mar-07 01:06   »» 
STTP
There's one bracket too many in my post.

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 28-Mar-07 20:25   »» 
Hey, I figured out a much better pi formula to use. I'm using a variation of Bowein's Algorithm, which converges cubically on 1/pi. I still can't get it to work though. It always says Pi=Infinity.

// Cubic conversion of Borwein's Algorithm
// Each iteration converges
// cubically against 1/pi;
// that is, each iteration
// approximately triples the
// number of correct digits.
// Program written by ROBO_HEN5000
// Algorithm complements of Wikipedia.

#include <iostream.h>
#include <math.h>

int main(void)
{
double pi;
double a;
double s;
double r;
double k;
int iterations;
int repetitions = 0;
cout << "How many iterations of the equation would you like?\n";
cout << "The first iteration yields 3.14.\nEach iteration triples the number of correct digits.";
cin >> iterations;
cout << "\nCalculating Pi...\n";

s = (sqrt(3)-1)/2;
a = 1/3;
while (iterations >= repetitions)
{
r = 3/(1+2*pow((1-pow(s,3.0)),(1/3)));
s = (r-1)/2;
a = pow(r,2)*a-pow(3,k)*(pow(r,2)-1);
repetitions++;
};
pi = 1/a;
cout << "Pi = " << pi;
cin >> "mstdjkssttfafs"; //Just to keep the window open
}

Could someone help, please?

~~~ROBO~~~

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 28-Mar-07 20:32   »» 
I would help, if I knew how:P

~mmaarrkkuuss~

cactus2

»» models

Re: Do you want to learn to program in C   posted: 28-Mar-07 21:30   »» 
No clue. Probably some accuracy problem.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 29-Mar-07 01:12   »» 
i cant get this to work rite. i want number1 to = a variable, number2 to = a variable, function to = a variable, and answer to = a variable.
can you show me what i did wrong, and fix it.

#include <stdio.h>
int main (void)
{
int answer=z;
float number1=w, number2=y;
char function=x;

{
printf("CALCULATOR\n");
printf("------------------------------\n \n");
printf("First number\n \n \t - ");
scanf("%f)", &number1);
printf("\n function, (e.g. +, -, /, *)\n \n \t - ");
scanf("%c", &function);
printf("Second Number\n \n \t - ");
scanf("%f", &number2);

answer = w x y = z;

printf("%d",z);
}
scanf("%c");
return 0;
}

thanks. and dail, can you explain a little more how to use it. i tried but it still dosent work.

thanks again.

matt wuz here

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 29-Mar-07 13:40   »» 
*bump*

I just got 25000 post!



This topic has 357 replies on 24 pages [ « | 1 ... 5 6 7 8 9 10 11 12 13 ... 24  | » ]


»» previous topic   »» next topic  

»» back to topic list  »» top of the page  

PLEASE READ THE FORUM GUIDELINES AND ALWAYS PREVIEW TO CHECK MESSAGES BEFORE POSTING...
...Help keep our forums creative and constructive. Thank you.


»» forum home