Thread: how to write this cout<< in C

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    51

    how to write this cout<< in C

    how to do write this in C

    Code:
     cout<<numbers[n]<<",";
    there are 5 elements in the numbers array. but when i write
    Code:
     printf("%d", numbers[n]);
    I only get the first number. ie 10.

    here is the whole code

    Code:
     #include <stdio.h>
    
    int main (){
    	int numbers[5];
    	int *p;
    	p = numbers;
    	
    	*p = 10;
    	p++;
    	*p = 20;
    	p = &numbers[2];
    	*p = 30;
    	p = numbers + 3;
    	*p = 40;
    	p = numbers;
    	*(p + 4) = 50;
    	
    	for (int n = 0; n<5; n++) {
    		//cout<<numbers[n]<<",";
    		printf("%d" , numbers[n]);
    		return 0;
    	}
    }

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    cause your return 0; is inside your for loop and thus it exits on the first iteration.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    51
    Oh,
    Yes thank you nonpuz.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-18-2006, 11:25 AM
  2. program to make a floppy write protected
    By shrijeetp in forum C Programming
    Replies: 1
    Last Post: 10-03-2005, 06:00 AM
  3. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 04:48 PM
  4. Function to write string 3 times
    By Giggs in forum C++ Programming
    Replies: 15
    Last Post: 12-24-2002, 04:00 PM
  5. write in c
    By PutoAmo in forum C Programming
    Replies: 6
    Last Post: 04-03-2002, 07:53 PM