How to fix this error ? '[Error] no match for 'operator[]' (operand types are 'empl' and 'int')'How to concatenate a std::string and an int?What does the C++ standard state the size of int, long type to be?error: request for member '..' in '..' which is of non-class typeHow to convert int to QString?Single line pointer operationsWhat is an undefined reference/unresolved external symbol error and how do I fix it?Type Casting File Input to Vector Type in C++Why I am getting two different outputs while using unsigned int and unsigned long int in C++No operator “==” matches these operands. operand types are: int == type_name`Character variable not getting printed correctly while using cin and cout
Does knowing that the exponent is in a certain range help solving discrete log?
What if a restaurant suddenly cannot accept credit cards, and the customer has no cash?
Can I use images from my published papers in my thesis without copyright infringment?
Have made several mistakes during the course of my PhD. Can't help but feel resentment. Can I get some advice about how to move forward?
Subgroup generated by a subgroup and a conjugate of it
Which manga depicts Doraemon and Nobita on Easter Island?
What exactly happened to the 18 crew members who were reported as "missing" in "Q Who"?
Ending a line of dialogue with "?!": Allowed or obnoxious?
What is the opposite of "hunger level"?
What would cause a nuclear power plant to break down after 2000 years, but not sooner?
μονάδαι as plural form of μονάς
A reccomended structured approach to self studying music theory for songwriting
Did Michelle Obama have a staff of 23; and Melania have a staff of 4?
If it isn't [someone's name]!
Meaning and structure of headline "Hair it is: A List of ..."
How does the illumination of the sky from the sun compare to that of the moon?
What should I do with the stock I own if I anticipate there will be a recession?
Icon is not displayed in lwc
Are there any OR challenges that are similar to kaggle's competitions?
Have there ever been other TV shows or Films that told a similiar story to the new 90210 show?
My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?
Adding things to bunches of things vs multiplication
Airline power sockets shut down when I plug my computer in. How can I avoid that?
Parse a simple key=value config file in C
How to fix this error ? '[Error] no match for 'operator[]' (operand types are 'empl' and 'int')'
How to concatenate a std::string and an int?What does the C++ standard state the size of int, long type to be?error: request for member '..' in '..' which is of non-class typeHow to convert int to QString?Single line pointer operationsWhat is an undefined reference/unresolved external symbol error and how do I fix it?Type Casting File Input to Vector Type in C++Why I am getting two different outputs while using unsigned int and unsigned long int in C++No operator “==” matches these operands. operand types are: int == type_name`Character variable not getting printed correctly while using cin and cout
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Im getting homework done but i faced this problem i tried everything changing variables name, changing function ....
is the problem because of the labels ?
#include<stdio.h>
#include<iostream>
struct empl
char nom;
char pre;
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int n)
printf("saisie la taille de tableauxn");
scanf("%dn", &n);
return 0;
int remplire(int n, struct empl t, int i)
for (i = 1; i <= n; i++)
printf("t[%d].nom= ", i);
scanf("%sn", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%sn", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%fn", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lfn", &t[i].cin);
int main()
int i, n;
int taille(int n),
taille(n);
int remplire(int n, struct empl t, int i);
remplire(n, t, i);
c++
add a comment |
Im getting homework done but i faced this problem i tried everything changing variables name, changing function ....
is the problem because of the labels ?
#include<stdio.h>
#include<iostream>
struct empl
char nom;
char pre;
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int n)
printf("saisie la taille de tableauxn");
scanf("%dn", &n);
return 0;
int remplire(int n, struct empl t, int i)
for (i = 1; i <= n; i++)
printf("t[%d].nom= ", i);
scanf("%sn", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%sn", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%fn", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lfn", &t[i].cin);
int main()
int i, n;
int taille(int n),
taille(n);
int remplire(int n, struct empl t, int i);
remplire(n, t, i);
c++
4
C or C++?#include <iostream>
andoperator[]
are both C++, but you tagged the question C. Which is it?
– Andrew Henle
Mar 27 at 13:23
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.
– Lundin
Mar 27 at 13:33
Don't mix apples and oranges.stdio.h
is a C header file.iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.
– machine_1
Mar 27 at 13:34
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36
add a comment |
Im getting homework done but i faced this problem i tried everything changing variables name, changing function ....
is the problem because of the labels ?
#include<stdio.h>
#include<iostream>
struct empl
char nom;
char pre;
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int n)
printf("saisie la taille de tableauxn");
scanf("%dn", &n);
return 0;
int remplire(int n, struct empl t, int i)
for (i = 1; i <= n; i++)
printf("t[%d].nom= ", i);
scanf("%sn", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%sn", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%fn", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lfn", &t[i].cin);
int main()
int i, n;
int taille(int n),
taille(n);
int remplire(int n, struct empl t, int i);
remplire(n, t, i);
c++
Im getting homework done but i faced this problem i tried everything changing variables name, changing function ....
is the problem because of the labels ?
#include<stdio.h>
#include<iostream>
struct empl
char nom;
char pre;
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int n)
printf("saisie la taille de tableauxn");
scanf("%dn", &n);
return 0;
int remplire(int n, struct empl t, int i)
for (i = 1; i <= n; i++)
printf("t[%d].nom= ", i);
scanf("%sn", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%sn", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%fn", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lfn", &t[i].cin);
int main()
int i, n;
int taille(int n),
taille(n);
int remplire(int n, struct empl t, int i);
remplire(n, t, i);
c++
c++
edited Mar 27 at 13:37
machine_1
2,7462 gold badges14 silver badges32 bronze badges
2,7462 gold badges14 silver badges32 bronze badges
asked Mar 27 at 13:22
Ghaith ZghidiGhaith Zghidi
64 bronze badges
64 bronze badges
4
C or C++?#include <iostream>
andoperator[]
are both C++, but you tagged the question C. Which is it?
– Andrew Henle
Mar 27 at 13:23
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.
– Lundin
Mar 27 at 13:33
Don't mix apples and oranges.stdio.h
is a C header file.iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.
– machine_1
Mar 27 at 13:34
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36
add a comment |
4
C or C++?#include <iostream>
andoperator[]
are both C++, but you tagged the question C. Which is it?
– Andrew Henle
Mar 27 at 13:23
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.
– Lundin
Mar 27 at 13:33
Don't mix apples and oranges.stdio.h
is a C header file.iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.
– machine_1
Mar 27 at 13:34
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36
4
4
C or C++?
#include <iostream>
and operator[]
are both C++, but you tagged the question C. Which is it?– Andrew Henle
Mar 27 at 13:23
C or C++?
#include <iostream>
and operator[]
are both C++, but you tagged the question C. Which is it?– Andrew Henle
Mar 27 at 13:23
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.– Lundin
Mar 27 at 13:33
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.– Lundin
Mar 27 at 13:33
Don't mix apples and oranges.
stdio.h
is a C header file. iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.– machine_1
Mar 27 at 13:34
Don't mix apples and oranges.
stdio.h
is a C header file. iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.– machine_1
Mar 27 at 13:34
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36
add a comment |
4 Answers
4
active
oldest
votes
Although your code is written mostly in C style, you seem to be compiling it with a C++ compiler, as it accepts #include <iostream>
(though you do not appear to use anything from it), and it has a notion of operator overloading. C and C++ are distinct languages, and the distinction is somewhat relevant here.
In either language, however, the code you have presented is flawed. The problem is with the several expressions in function remplire
that follow this pattern: &t[i].nom
. Absent any operator overloading (which is not available in C anyway), the []
operator in those expressions requires one of its operands to designate either a pointer or an array, and the other to designate an integer. Although there is a file-scope variable t
that is an array, inside remplire()
that is shadowed by a function parameter with the same name. Inside that function, then, t
refers the the parameter, which is a struct empl
, not an array or pointer (or integer).
Your compiler ought to be giving you another clue, too, where you call that function ...
remplire(n,t,i);
..., passing the global t
as an argument. The compiler very much should complain about a type mismatch between the second argument (t
) and the corresponding function parameter.
Perhaps what you wanted to do is simply to declare remplire()
to accept a structure pointer as its second parameter:
int remplire(int n, struct empl *t, int i)
While you're at it, do remove the redundant local declaration of that function inside main()
. You don't need that as long as remplire()
is defined before main()
, and if you want to have a separate declaration of that function then it would best be placed at file scope, and probably in a header file.
add a comment |
First of all iostream
is C++ header coming from standard library and will not work for C program. And now issues:
int taille (int n)
printf("saisie la taille de tableauxn");
scanf("%dn",&n);
return 0;
This function is called with an input parameter - that means you can pass a value into a function, but not access the parameter and hope it will be used in other places. To correct this you should declare the function should look like this:
int taille (int * n)
printf("saisie la taille de tableauxn");
scanf("%dn", n);
return 0;
Next function - similar problem, it should look like this:
int remplire (int n , struct empl * t ,int i)
for (i=1;i<=n;i++)
printf("t[%d].nom= ",i);
scanf("%sn",&t[i].nom);
printf("t[%d].prenom= ",i);
scanf("%sn",&t[i].pre);
printf("t[%d].salaire= ",i);
scanf("%fn",&t[i].salaire);
printf("t[%d].CIN= ",i);
scanf("%lfn",&t[i].cin);
Or even like this:
int remplire (int n , int i)
as t
is global variable. Also this function should return some value as it is declared to return int
.
And now the main
function:
int main()
int i,n;
int taille(int n),
taille(n);
int remplire(int n,struct empl t,int i);
remplire(n,t,i);
Don't redeclare functions inside another function, even if it is permissible it does not mean you should do it. Also main function should return 0 if everything works fine. To correct the function write it like this:
int main()
int i,n;
taille(& n);
remplire(n,& t,i);
Some good advice, please read some books to learn how to program in C if you want to go that way.
add a comment |
There are many issues in your code.
Starting reading a good C textbook is advised.
You probably want this:
#include <stdio.h>
#include <iostream>
struct empl
char nom[30];
char pre[30];
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int & n)
printf("saisie la taille de tableauxn");
scanf("%d", &n);
return 0;
void remplire(int n, struct empl *t)
for (int i = 0; i < n; i++)
printf("t[%d].nom= ", i);
scanf("%s", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%s", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%f", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lf", &t[i].cin);
int main()
int n;
taille(n);
remplire(n, t);
It's still poor code and it's written mostly in C style, but it compiles and works as intended.
In C++ you'd do this totally differently.
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
add a comment |
You've declared this global array variable t
struct empl t[50];
and also declared a parameter t
in this function
int remplire (int n , struct empl t ,int i)
Inside the function it's going to treat any instance of t
as to be the parameter as that is nearer in scope than the global variable. So when you have code like this...
scanf("%sn",&t[i].nom);
...it's going to throw up errors because t
isn't an array.
The solution is to use variable names that have meaning like "employee_array" rather than single letters.
Also that call to scanf
is wrong as for strings you don't need to pass in a pointer to the variable, so it should look like
scanf("%sn",t[i].nom);
But you'd also need to make nom
be a string too - currently it's only a char.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378280%2fhow-to-fix-this-error-error-no-match-for-operator-operand-types-are-e%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Although your code is written mostly in C style, you seem to be compiling it with a C++ compiler, as it accepts #include <iostream>
(though you do not appear to use anything from it), and it has a notion of operator overloading. C and C++ are distinct languages, and the distinction is somewhat relevant here.
In either language, however, the code you have presented is flawed. The problem is with the several expressions in function remplire
that follow this pattern: &t[i].nom
. Absent any operator overloading (which is not available in C anyway), the []
operator in those expressions requires one of its operands to designate either a pointer or an array, and the other to designate an integer. Although there is a file-scope variable t
that is an array, inside remplire()
that is shadowed by a function parameter with the same name. Inside that function, then, t
refers the the parameter, which is a struct empl
, not an array or pointer (or integer).
Your compiler ought to be giving you another clue, too, where you call that function ...
remplire(n,t,i);
..., passing the global t
as an argument. The compiler very much should complain about a type mismatch between the second argument (t
) and the corresponding function parameter.
Perhaps what you wanted to do is simply to declare remplire()
to accept a structure pointer as its second parameter:
int remplire(int n, struct empl *t, int i)
While you're at it, do remove the redundant local declaration of that function inside main()
. You don't need that as long as remplire()
is defined before main()
, and if you want to have a separate declaration of that function then it would best be placed at file scope, and probably in a header file.
add a comment |
Although your code is written mostly in C style, you seem to be compiling it with a C++ compiler, as it accepts #include <iostream>
(though you do not appear to use anything from it), and it has a notion of operator overloading. C and C++ are distinct languages, and the distinction is somewhat relevant here.
In either language, however, the code you have presented is flawed. The problem is with the several expressions in function remplire
that follow this pattern: &t[i].nom
. Absent any operator overloading (which is not available in C anyway), the []
operator in those expressions requires one of its operands to designate either a pointer or an array, and the other to designate an integer. Although there is a file-scope variable t
that is an array, inside remplire()
that is shadowed by a function parameter with the same name. Inside that function, then, t
refers the the parameter, which is a struct empl
, not an array or pointer (or integer).
Your compiler ought to be giving you another clue, too, where you call that function ...
remplire(n,t,i);
..., passing the global t
as an argument. The compiler very much should complain about a type mismatch between the second argument (t
) and the corresponding function parameter.
Perhaps what you wanted to do is simply to declare remplire()
to accept a structure pointer as its second parameter:
int remplire(int n, struct empl *t, int i)
While you're at it, do remove the redundant local declaration of that function inside main()
. You don't need that as long as remplire()
is defined before main()
, and if you want to have a separate declaration of that function then it would best be placed at file scope, and probably in a header file.
add a comment |
Although your code is written mostly in C style, you seem to be compiling it with a C++ compiler, as it accepts #include <iostream>
(though you do not appear to use anything from it), and it has a notion of operator overloading. C and C++ are distinct languages, and the distinction is somewhat relevant here.
In either language, however, the code you have presented is flawed. The problem is with the several expressions in function remplire
that follow this pattern: &t[i].nom
. Absent any operator overloading (which is not available in C anyway), the []
operator in those expressions requires one of its operands to designate either a pointer or an array, and the other to designate an integer. Although there is a file-scope variable t
that is an array, inside remplire()
that is shadowed by a function parameter with the same name. Inside that function, then, t
refers the the parameter, which is a struct empl
, not an array or pointer (or integer).
Your compiler ought to be giving you another clue, too, where you call that function ...
remplire(n,t,i);
..., passing the global t
as an argument. The compiler very much should complain about a type mismatch between the second argument (t
) and the corresponding function parameter.
Perhaps what you wanted to do is simply to declare remplire()
to accept a structure pointer as its second parameter:
int remplire(int n, struct empl *t, int i)
While you're at it, do remove the redundant local declaration of that function inside main()
. You don't need that as long as remplire()
is defined before main()
, and if you want to have a separate declaration of that function then it would best be placed at file scope, and probably in a header file.
Although your code is written mostly in C style, you seem to be compiling it with a C++ compiler, as it accepts #include <iostream>
(though you do not appear to use anything from it), and it has a notion of operator overloading. C and C++ are distinct languages, and the distinction is somewhat relevant here.
In either language, however, the code you have presented is flawed. The problem is with the several expressions in function remplire
that follow this pattern: &t[i].nom
. Absent any operator overloading (which is not available in C anyway), the []
operator in those expressions requires one of its operands to designate either a pointer or an array, and the other to designate an integer. Although there is a file-scope variable t
that is an array, inside remplire()
that is shadowed by a function parameter with the same name. Inside that function, then, t
refers the the parameter, which is a struct empl
, not an array or pointer (or integer).
Your compiler ought to be giving you another clue, too, where you call that function ...
remplire(n,t,i);
..., passing the global t
as an argument. The compiler very much should complain about a type mismatch between the second argument (t
) and the corresponding function parameter.
Perhaps what you wanted to do is simply to declare remplire()
to accept a structure pointer as its second parameter:
int remplire(int n, struct empl *t, int i)
While you're at it, do remove the redundant local declaration of that function inside main()
. You don't need that as long as remplire()
is defined before main()
, and if you want to have a separate declaration of that function then it would best be placed at file scope, and probably in a header file.
edited Mar 27 at 15:06
answered Mar 27 at 13:41
John BollingerJohn Bollinger
95.7k8 gold badges48 silver badges91 bronze badges
95.7k8 gold badges48 silver badges91 bronze badges
add a comment |
add a comment |
First of all iostream
is C++ header coming from standard library and will not work for C program. And now issues:
int taille (int n)
printf("saisie la taille de tableauxn");
scanf("%dn",&n);
return 0;
This function is called with an input parameter - that means you can pass a value into a function, but not access the parameter and hope it will be used in other places. To correct this you should declare the function should look like this:
int taille (int * n)
printf("saisie la taille de tableauxn");
scanf("%dn", n);
return 0;
Next function - similar problem, it should look like this:
int remplire (int n , struct empl * t ,int i)
for (i=1;i<=n;i++)
printf("t[%d].nom= ",i);
scanf("%sn",&t[i].nom);
printf("t[%d].prenom= ",i);
scanf("%sn",&t[i].pre);
printf("t[%d].salaire= ",i);
scanf("%fn",&t[i].salaire);
printf("t[%d].CIN= ",i);
scanf("%lfn",&t[i].cin);
Or even like this:
int remplire (int n , int i)
as t
is global variable. Also this function should return some value as it is declared to return int
.
And now the main
function:
int main()
int i,n;
int taille(int n),
taille(n);
int remplire(int n,struct empl t,int i);
remplire(n,t,i);
Don't redeclare functions inside another function, even if it is permissible it does not mean you should do it. Also main function should return 0 if everything works fine. To correct the function write it like this:
int main()
int i,n;
taille(& n);
remplire(n,& t,i);
Some good advice, please read some books to learn how to program in C if you want to go that way.
add a comment |
First of all iostream
is C++ header coming from standard library and will not work for C program. And now issues:
int taille (int n)
printf("saisie la taille de tableauxn");
scanf("%dn",&n);
return 0;
This function is called with an input parameter - that means you can pass a value into a function, but not access the parameter and hope it will be used in other places. To correct this you should declare the function should look like this:
int taille (int * n)
printf("saisie la taille de tableauxn");
scanf("%dn", n);
return 0;
Next function - similar problem, it should look like this:
int remplire (int n , struct empl * t ,int i)
for (i=1;i<=n;i++)
printf("t[%d].nom= ",i);
scanf("%sn",&t[i].nom);
printf("t[%d].prenom= ",i);
scanf("%sn",&t[i].pre);
printf("t[%d].salaire= ",i);
scanf("%fn",&t[i].salaire);
printf("t[%d].CIN= ",i);
scanf("%lfn",&t[i].cin);
Or even like this:
int remplire (int n , int i)
as t
is global variable. Also this function should return some value as it is declared to return int
.
And now the main
function:
int main()
int i,n;
int taille(int n),
taille(n);
int remplire(int n,struct empl t,int i);
remplire(n,t,i);
Don't redeclare functions inside another function, even if it is permissible it does not mean you should do it. Also main function should return 0 if everything works fine. To correct the function write it like this:
int main()
int i,n;
taille(& n);
remplire(n,& t,i);
Some good advice, please read some books to learn how to program in C if you want to go that way.
add a comment |
First of all iostream
is C++ header coming from standard library and will not work for C program. And now issues:
int taille (int n)
printf("saisie la taille de tableauxn");
scanf("%dn",&n);
return 0;
This function is called with an input parameter - that means you can pass a value into a function, but not access the parameter and hope it will be used in other places. To correct this you should declare the function should look like this:
int taille (int * n)
printf("saisie la taille de tableauxn");
scanf("%dn", n);
return 0;
Next function - similar problem, it should look like this:
int remplire (int n , struct empl * t ,int i)
for (i=1;i<=n;i++)
printf("t[%d].nom= ",i);
scanf("%sn",&t[i].nom);
printf("t[%d].prenom= ",i);
scanf("%sn",&t[i].pre);
printf("t[%d].salaire= ",i);
scanf("%fn",&t[i].salaire);
printf("t[%d].CIN= ",i);
scanf("%lfn",&t[i].cin);
Or even like this:
int remplire (int n , int i)
as t
is global variable. Also this function should return some value as it is declared to return int
.
And now the main
function:
int main()
int i,n;
int taille(int n),
taille(n);
int remplire(int n,struct empl t,int i);
remplire(n,t,i);
Don't redeclare functions inside another function, even if it is permissible it does not mean you should do it. Also main function should return 0 if everything works fine. To correct the function write it like this:
int main()
int i,n;
taille(& n);
remplire(n,& t,i);
Some good advice, please read some books to learn how to program in C if you want to go that way.
First of all iostream
is C++ header coming from standard library and will not work for C program. And now issues:
int taille (int n)
printf("saisie la taille de tableauxn");
scanf("%dn",&n);
return 0;
This function is called with an input parameter - that means you can pass a value into a function, but not access the parameter and hope it will be used in other places. To correct this you should declare the function should look like this:
int taille (int * n)
printf("saisie la taille de tableauxn");
scanf("%dn", n);
return 0;
Next function - similar problem, it should look like this:
int remplire (int n , struct empl * t ,int i)
for (i=1;i<=n;i++)
printf("t[%d].nom= ",i);
scanf("%sn",&t[i].nom);
printf("t[%d].prenom= ",i);
scanf("%sn",&t[i].pre);
printf("t[%d].salaire= ",i);
scanf("%fn",&t[i].salaire);
printf("t[%d].CIN= ",i);
scanf("%lfn",&t[i].cin);
Or even like this:
int remplire (int n , int i)
as t
is global variable. Also this function should return some value as it is declared to return int
.
And now the main
function:
int main()
int i,n;
int taille(int n),
taille(n);
int remplire(int n,struct empl t,int i);
remplire(n,t,i);
Don't redeclare functions inside another function, even if it is permissible it does not mean you should do it. Also main function should return 0 if everything works fine. To correct the function write it like this:
int main()
int i,n;
taille(& n);
remplire(n,& t,i);
Some good advice, please read some books to learn how to program in C if you want to go that way.
answered Mar 27 at 13:37
DiodacusDiodacus
6348 bronze badges
6348 bronze badges
add a comment |
add a comment |
There are many issues in your code.
Starting reading a good C textbook is advised.
You probably want this:
#include <stdio.h>
#include <iostream>
struct empl
char nom[30];
char pre[30];
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int & n)
printf("saisie la taille de tableauxn");
scanf("%d", &n);
return 0;
void remplire(int n, struct empl *t)
for (int i = 0; i < n; i++)
printf("t[%d].nom= ", i);
scanf("%s", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%s", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%f", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lf", &t[i].cin);
int main()
int n;
taille(n);
remplire(n, t);
It's still poor code and it's written mostly in C style, but it compiles and works as intended.
In C++ you'd do this totally differently.
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
add a comment |
There are many issues in your code.
Starting reading a good C textbook is advised.
You probably want this:
#include <stdio.h>
#include <iostream>
struct empl
char nom[30];
char pre[30];
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int & n)
printf("saisie la taille de tableauxn");
scanf("%d", &n);
return 0;
void remplire(int n, struct empl *t)
for (int i = 0; i < n; i++)
printf("t[%d].nom= ", i);
scanf("%s", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%s", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%f", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lf", &t[i].cin);
int main()
int n;
taille(n);
remplire(n, t);
It's still poor code and it's written mostly in C style, but it compiles and works as intended.
In C++ you'd do this totally differently.
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
add a comment |
There are many issues in your code.
Starting reading a good C textbook is advised.
You probably want this:
#include <stdio.h>
#include <iostream>
struct empl
char nom[30];
char pre[30];
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int & n)
printf("saisie la taille de tableauxn");
scanf("%d", &n);
return 0;
void remplire(int n, struct empl *t)
for (int i = 0; i < n; i++)
printf("t[%d].nom= ", i);
scanf("%s", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%s", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%f", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lf", &t[i].cin);
int main()
int n;
taille(n);
remplire(n, t);
It's still poor code and it's written mostly in C style, but it compiles and works as intended.
In C++ you'd do this totally differently.
There are many issues in your code.
Starting reading a good C textbook is advised.
You probably want this:
#include <stdio.h>
#include <iostream>
struct empl
char nom[30];
char pre[30];
float salaire;
double cin;
empl;
struct empl t[50];
struct empl E;
int taille(int & n)
printf("saisie la taille de tableauxn");
scanf("%d", &n);
return 0;
void remplire(int n, struct empl *t)
for (int i = 0; i < n; i++)
printf("t[%d].nom= ", i);
scanf("%s", &t[i].nom);
printf("t[%d].prenom= ", i);
scanf("%s", &t[i].pre);
printf("t[%d].salaire= ", i);
scanf("%f", &t[i].salaire);
printf("t[%d].CIN= ", i);
scanf("%lf", &t[i].cin);
int main()
int n;
taille(n);
remplire(n, t);
It's still poor code and it's written mostly in C style, but it compiles and works as intended.
In C++ you'd do this totally differently.
edited Mar 27 at 13:42
answered Mar 27 at 13:37
JabberwockyJabberwocky
29.6k10 gold badges43 silver badges77 bronze badges
29.6k10 gold badges43 silver badges77 bronze badges
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
add a comment |
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
Thanks im a beginner in c++ and im learning by my self so i face many problems i usually google the problem and i get the solution but not this time however thank you
– Ghaith Zghidi
Mar 27 at 13:40
add a comment |
You've declared this global array variable t
struct empl t[50];
and also declared a parameter t
in this function
int remplire (int n , struct empl t ,int i)
Inside the function it's going to treat any instance of t
as to be the parameter as that is nearer in scope than the global variable. So when you have code like this...
scanf("%sn",&t[i].nom);
...it's going to throw up errors because t
isn't an array.
The solution is to use variable names that have meaning like "employee_array" rather than single letters.
Also that call to scanf
is wrong as for strings you don't need to pass in a pointer to the variable, so it should look like
scanf("%sn",t[i].nom);
But you'd also need to make nom
be a string too - currently it's only a char.
add a comment |
You've declared this global array variable t
struct empl t[50];
and also declared a parameter t
in this function
int remplire (int n , struct empl t ,int i)
Inside the function it's going to treat any instance of t
as to be the parameter as that is nearer in scope than the global variable. So when you have code like this...
scanf("%sn",&t[i].nom);
...it's going to throw up errors because t
isn't an array.
The solution is to use variable names that have meaning like "employee_array" rather than single letters.
Also that call to scanf
is wrong as for strings you don't need to pass in a pointer to the variable, so it should look like
scanf("%sn",t[i].nom);
But you'd also need to make nom
be a string too - currently it's only a char.
add a comment |
You've declared this global array variable t
struct empl t[50];
and also declared a parameter t
in this function
int remplire (int n , struct empl t ,int i)
Inside the function it's going to treat any instance of t
as to be the parameter as that is nearer in scope than the global variable. So when you have code like this...
scanf("%sn",&t[i].nom);
...it's going to throw up errors because t
isn't an array.
The solution is to use variable names that have meaning like "employee_array" rather than single letters.
Also that call to scanf
is wrong as for strings you don't need to pass in a pointer to the variable, so it should look like
scanf("%sn",t[i].nom);
But you'd also need to make nom
be a string too - currently it's only a char.
You've declared this global array variable t
struct empl t[50];
and also declared a parameter t
in this function
int remplire (int n , struct empl t ,int i)
Inside the function it's going to treat any instance of t
as to be the parameter as that is nearer in scope than the global variable. So when you have code like this...
scanf("%sn",&t[i].nom);
...it's going to throw up errors because t
isn't an array.
The solution is to use variable names that have meaning like "employee_array" rather than single letters.
Also that call to scanf
is wrong as for strings you don't need to pass in a pointer to the variable, so it should look like
scanf("%sn",t[i].nom);
But you'd also need to make nom
be a string too - currently it's only a char.
answered Mar 27 at 13:37
Chris TurnerChris Turner
7,4791 gold badge12 silver badges18 bronze badges
7,4791 gold badge12 silver badges18 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378280%2fhow-to-fix-this-error-error-no-match-for-operator-operand-types-are-e%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
C or C++?
#include <iostream>
andoperator[]
are both C++, but you tagged the question C. Which is it?– Andrew Henle
Mar 27 at 13:23
char nom
is a single character not a string. I'd recommend getting a good C programming book, you can't learn by trial & error.– Lundin
Mar 27 at 13:33
Don't mix apples and oranges.
stdio.h
is a C header file.iostream
is a C++ header file. Restrict yourself to one language as the two are quite different.– machine_1
Mar 27 at 13:34
sorry guys miss click its c++
– Ghaith Zghidi
Mar 27 at 13:36