C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-22-2009, 04:54 PM   #1
Registered User
 
Join Date: Jan 2009
Posts: 13
Angry For Loop Disaster

Currently trying how to use the For loop but I知 not having much luck. Just trying to print a name ten times but I reckon I知 doing something wrong? Your help would be much appreciate as i am getting very frustrated!

Code:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

char name[25];
void input_name()
{
     printf("please enter your name.");
     scanf("s%",&name);
}
void process()
{
for (name=1; <10; name+1)
    printf("Your name is %s/n",name);
}

int main()
{
    input_name();
    process();
    getch();
    return 1;
}
Chalmers86 is offline   Reply With Quote
Old 03-22-2009, 04:55 PM   #2
Registered User
 
Join Date: Jan 2009
Posts: 13
sorry didn't mean to create two. If possible could the admin delete this sorry to make a mess.
Chalmers86 is offline   Reply With Quote
Old 03-22-2009, 05:00 PM   #3
Registered User
 
Join Date: Oct 2008
Posts: 452
Do you know about while loops? I think you should learn about those first. Then, all you really need to know is that:
Code:
for(A; B; C) {
  D;
}
Is identical to:
Code:
A;
while(B) {
  D;
  C;
}
So in for, you specify three... let's refer to them as arguments, even though they aren't, really. The first is executed before the for loop is executed, the second is the while condition, and the third is executed whenever the loop's body is executed (so at the end of the body, after every iteration).

So, now, how do you think you should do it?
EVOEx is offline   Reply With Quote
Old 03-22-2009, 05:20 PM   #4
Registered User
 
Join Date: Jan 2009
Posts: 13
I’ve done a little on while loops but I’m not that experienced in C programming as a whole. This is my first year at college.

I understand what you have wrote there.

I’ve been taught for the for loop that –

For(initialisation; test condition; Incrementation or decrementation)

Which I kinda understand but what is initialisation? I put name=1 cause I thought you had to tell the computer that name was one thing and the rest told the computer add to one till you reach ten.

I understand the while loop is definitely the most logical way of solving this problem but I’m just trying to understand the for loop so I can incorporate it in another program.

I understand the theory behind the language but can put it into code. If that makes sense?
Chalmers86 is offline   Reply With Quote
Reply

Tags
problem

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
For Loop Disaster Chalmers86 C Programming 4 03-23-2009 12:58 AM
Tsunami disaster. anonytmouse A Brief History of Cprogramming.com 23 01-09-2005 09:56 AM
NTFS disaster recovery -=SoKrA=- Tech Board 20 04-17-2004 02:16 AM
Class + Union + Struct = Disaster?? Inquirer C++ Programming 5 10-28-2002 03:55 PM
disaster relief iain A Brief History of Cprogramming.com 1 09-13-2001 08:12 PM


All times are GMT -6. The time now is 05:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22