i don't know where is the problem !

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 830 Views - Last Post: 06 January 2013 - 01:23 AM Rate Topic: -----

#1 miroucha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-November 12

i don't know where is the problem !

Posted 07 November 2012 - 01:05 PM

#include <StdAfx.h>
#include<stdio.h>

	int main(){
char t_titre[20]={"les mesirables","la terre","l'aveuglement","le chateau","molloy","l'idiot","l'lliade","le faim","l'etranger"};
int t_nbreexp[20]={10,14,12,15,7,6,10,13,8};
int t_livre[20]={1010,1011,1012,1013,1014,1015,1016,1017,1018};
int i;
{
	for(i=0,i<=19,i++)
printf("la valeur est");
scanf("%s",t_titre);
}

{
	for(i=0,i<=19,i++)
printf("la valeur est");
scanf("%i",&t_nbreexp);
}

{
	for(i=0,i<=19,i++)
printf("la valeur");
scanf("%i",&t_livre);
}
return 0
	}

This post has been edited by modi123_1: 07 November 2012 - 01:06 PM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: i don't know where is the problem !

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9574
  • View blog
  • Posts: 36,268
  • Joined: 12-June 08

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:08 PM

Let's start with "what *IS* the problem?" and go from there. Are you getting an error? If so what is the error text and line it is occurring on? Is the program behaving not as expected? If so what is it doing and what should it be doing?

Just saying "I have a problem" is a slothful option to take, but if you communicate more and provide a bit of information upfront you help people to help you. Capiche?
Was This Post Helpful? 0
  • +
  • -

#3 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 98
  • Joined: 15-April 10

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:09 PM

And what is the problem?

What are you trying to do, what are you inputting, what are you expecting, what is the program outputting and what errors or warnings does the compiler give?
Was This Post Helpful? 0
  • +
  • -

#4 miroucha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-November 12

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:15 PM

View PostKBoogle, on 07 November 2012 - 01:09 PM, said:

And what is the problem?

What are you trying to do, what are you inputting, what are you expecting, what is the program outputting and what errors or warnings does the compiler give?


This program allows you to fill the three tables and display by following, there's one mistake it is " c2078:too many initializers" !!!
Was This Post Helpful? 0
  • +
  • -

#5 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 625
  • Joined: 11-June 11

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:18 PM

Is this allowed?
char t_titre[20]={"les mesirables","la terre","l'aveuglement","le chateau","molloy","l'idiot","l'lliade","le faim","l'etranger"};


Assigning C String to char array...
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:22 PM

The problem probably starts here:

char t_titre[20]={"les mesirables","la terre","l'aveuglement","le chateau","molloy","l'idiot","l'lliade","le faim","l'etranger"};


You have defined t_titre as an array of 20 characters, not an array of 20 strings. A char can only hold one character. You probably want to create an array of strings:

   const char t_titre[][20]= {"les mesirables","la terre",
                              "l'aveuglement","le chateau","molloy",
                              "l'idiot","l'lliade","le faim","l'etranger"
                             };



Jim
Was This Post Helpful? 1
  • +
  • -

#7 miroucha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-November 12

Re: i don't know where is the problem !

Posted 07 November 2012 - 01:29 PM

View Postjimblumberg, on 07 November 2012 - 01:22 PM, said:

The problem probably starts here:

char t_titre[20]={"les mesirables","la terre","l'aveuglement","le chateau","molloy","l'idiot","l'lliade","le faim","l'etranger"};


You have defined t_titre as an array of 20 characters, not an array of 20 strings. A char can only hold one character. You probably want to create an array of strings:

   const char t_titre[][20]= {"les mesirables","la terre",
                              "l'aveuglement","le chateau","molloy",
                              "l'idiot","l'lliade","le faim","l'etranger"
                             };



Jim



thnx it works , but when I compiled it shows me nothing like the print screen shows they are no tables !!!!!!!
Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: i don't know where is the problem !

Posted 07 November 2012 - 02:09 PM

Hi, scanf reads in data from the keyboard, and printf displays values on the screen.

10    for(i=0,i<=19,i++)
      {
11      printf("la valeur est : %s \n", t_titre);
      }


Was This Post Helpful? 0
  • +
  • -

#9 miroucha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-November 12

Re: i don't know where is the problem !

Posted 07 November 2012 - 02:17 PM

View Post#define, on 07 November 2012 - 02:09 PM, said:

Hi, scanf reads in data from the keyboard, and printf displays values on the screen.

10    for(i=0,i<=19,i++)
      {
11      printf("la valeur est : %s \n", t_titre);
      }


same problem !! i don't know why when i compiled it there's the empty window "pres any key to continue' there is no tables !!
Was This Post Helpful? 0
  • +
  • -

#10 ivaylo9603  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 05-November 12

Re: i don't know where is the problem !

Posted 07 November 2012 - 02:25 PM

scanf() needs the adress of the variable you want to asign values to, e.g.

for(i=0,i<=19,i++)
2	      {
3	11      printf("la valeur est : %s \n", [b]&t_titre[/b]);
4	      }


Edit:
for(i=0,i<=19,i++)
    {
      printf("la valeur est : %s \n", &t_titre);
    }


Was This Post Helpful? 0
  • +
  • -

#11 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: i don't know where is the problem !

Posted 07 November 2012 - 02:25 PM

Oops, I forgot the subscript and index on the array of strings.

  for(i=0,i<=19,i++)
  {
    printf("la valeur est : %s \n", t_titre[i]);
  }


Was This Post Helpful? 0
  • +
  • -

#12 ivaylo9603  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 05-November 12

Re: i don't know where is the problem !

Posted 07 November 2012 - 02:26 PM

Was intended for scanf(), please don't mind this/ delete it.
Was This Post Helpful? 0
  • +
  • -

#13 miroucha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-November 12

Re: i don't know where is the problem !

Posted 08 November 2012 - 10:42 AM

#
include<stdio.h>;

int main(){
const char t_titre[][20]= {"les mesirables","la terre",

                           "l'aveuglement","le chateau","molloy",

                           "l'idiot","l'lliade","le faim","l'etranger"
                         };

int t_nbreexp[20];
int t_livre[20],i;

t_nbreexp[0]=10;
t_nbreexp[1]=12;
t_nbreexp[2]=9;
t_nbreexp[3]=11;
t_nbreexp[4]=13;
t_nbreexp[5]=8;
t_nbreexp[6]=9;
t_nbreexp[7]=7;
t_nbreexp[8]=5;

	for(;i=0,i<=19,i++;)/>
	{
		
printf("la valeur est : %i \n",t_titre[20]);
	}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",&t_nbreexp[20]);
}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",&t_livre[20]);
}
return 0;


	}

This post has been edited by jimblumberg: 08 November 2012 - 11:12 AM
Reason for edit:: Added missing Code Tags, Please learn to use them. Duplicate topics merged.

Was This Post Helpful? 0
  • +
  • -

#14 ivaylo9603  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 05-November 12

Re: i don't know where is the problem !

Posted 08 November 2012 - 10:57 AM

When you print values in cycles, you always print a null value from your array. set the array to the current for cycle variable

Sent from my GT-P3110

#include<stdio.h>;

int main(){
const char t_titre[][20]= {"les mesirables","la terre",

                           "l'aveuglement","le chateau","molloy",

                           "l'idiot","l'lliade","le faim","l'etranger"
                         };

int t_nbreexp[20];
int t_livre[20],i;

t_nbreexp[0]=10;
t_nbreexp[1]=12;
t_nbreexp[2]=9;
t_nbreexp[3]=11;
t_nbreexp[4]=13;
t_nbreexp[5]=8;
t_nbreexp[6]=9;
t_nbreexp[7]=7;
t_nbreexp[8]=5;

	for(;i=0,i<=19,i++;)/>
	{
		
printf("la valeur est : %i \n",t_titre[20]);
	}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",&t_nbreexp[20]);
}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",&t_livre[20]);
}




So as you've only assigned arrays from 0-8, the 20th has nothing in it hence not showing up i the cycle. Also you tend to print variables' adress. I beleve what you intended to do was :
for(;i=0,i<=19,i++;)/>
	{
		
printf("la valeur est : %i \n",t_titre[i]);
	}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",t_nbreexp[i]);
}


	for(;i=0,i<=19,i++;)/>
	{
printf("la valeur est : %i \n",t_livre[i]);
}



Sent from my GT-P3110

This post has been edited by jimblumberg: 08 November 2012 - 11:11 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.

Was This Post Helpful? 0
  • +
  • -

#15 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 625
  • Joined: 11-June 11

Re: i don't know where is the problem !

Posted 08 November 2012 - 11:10 AM

Please use code tags when posting some code... Just select your code and click the code button.. or write the code tags manually as:
// opening code tag
    [code]
         // code goes here
    [ /code]
// closing code tag



And, you have asked the same question in your previous thread you have opened for the same problem, and you have got an answer too... Have you checked that before opening a new thread? Please do not open new threads for the same problem. Just use the thread you have already opened.

Here is the thread and it contains the answer for your current problem...

PS: ivaylo9603 if you can wrap one piece of code in code tags, then why not the other code in the same post?


PS: I think the thread is merged by jimblumberg...

This post has been edited by AKMafia001: 08 November 2012 - 11:13 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2