Okay, so for my program, I need it to take input and put it into an array if the same thing string is not found within that array.
For example: First input is apples, the program searches through the list, and doesn't find apples, so it adds apples somewhere (I'm not sure where to add it to the array, as I'm not used to not being able to .append stuff to a list like in python).
Now the second input is oranges, oranges is found in the array, so it doesn't add it again.
I wrote like a test code that would try something like that, but it's just a basic algorithm that I can't get to work:
int yes = 0; // 0 means not found, 1 means found
while (size < capacity) // while the size (current element) is less than
// capacity of the list
{
if (*names == name)
{
yes = 1;
}
else yes = 0;
size++;
}
size = 0;
if (yes == 1){
// do something here
}
else *names = name; // add the name to the array
cout << *names;
Does this even make sense? lol
Note that I'm using loops, because this is beginners programming and we're not allowed to use anything we haven't learned in class.
Afaik C++ doesn't exclude C.
Some parts of C++ are often very useful, but many parts of C++ implicit unnecessary procedures, which I do not need here for example.
[EDIT]You should even find every part of the code above in the C++ tutorial or in the C++ reference of this C++ website[/EDIT]
I`m fully aware of that, I don`t think anyone is debating whether or not it is possible to use C in C++. But the point is, when the very intelligent people who made this site wrote their tutorial to teach C++, they omitted the C stuff. And on these boards we are supposed to be doing the same, teaching c++. Do you really think that if the TS of this thread handed in your solution to his instructor he would get 100%? No, he is going to probably get failed for blatant plagiarism because he copied someone else's code. That isn't very helpful of you to do to him.
C is part of C++ and therefore included in the stadnard library. There was nothing to be omitted.
This is also the reason why it is not called D, but C and an expansion of C (++).
As for the rest you are contradicting yourself. You say he does not get 100% if he copied this post and he would probalbly fail because of copying the code. He can't copy the code since his teacher certainly expects him to use other functions for the output as well as most probably for the memory allocation. The failure of realloc is not considered in the code above too. This is also something he would have to do himself.
At last, if he really were as stupid as to hand in a copy of the code above without to rewrite it in his own way he would definitely deserve a fail.
Gee that's some real Nancy Drew work there, Nancy. If you read my post
I don`t think anyone is debating whether or not it is possible to use C in C++
you would see that
I`m fully aware of that
.
his teacher certainly expects him to use other functions for the output as well as most probably for the memory allocation
So you gave him completely useless and overly convoluted code then? Because you sure didn't explain any of that code to him so he could substitute the stupid things you told him to do with a real solution, you just posted the code and said "Here, this is how it's done". What else can he do besides copy it?
As Helios told you a couple of days ago:
jmc: Are you trying to break some sort of "most bad advices given in a single day" record or something?
Jmc, the point still stands that this is a C++ forum. C isn't part of C++. They're two seperate languages. C++ is a superset of C, it is true, but there is some major differences. Not all C functions are included in C++ as standard.
So again, why post "pure C" on a C++ forum? It doesn't make a lick of sense.
Also, why are you trying to get him to use pointers? He states that he can't use anything he's not yet learned in class; if he had learnt pointers then he would be using pointers. So you're going to get him a fail anyway, even if he doesn't plagiarise your code.
1. He uses pointers in his example code.
2. Give me an example how it could be realised withoud using addresses (pointers).
3. Where the hell did you all learn that C is not part of C++ (sry for generalising and being so rude). Even Wikipedia will tell you it is. I hope you agree on this point:It was developed by Bjarne Stroustrup. If you don't I can't help you. If you do get a proper book from him like "Bjarne Stroustrup - The C++ Programming Language - 3rd edition" or "Bjarne Stroustrup - The Design and Evolution of C++". You can even find it on http://www.research.att.com/~bs/homepage.html.
If your opinion is still that "C is not part of C++" and "C++ is a better C is wrong" and "C++ is not an extension of C" then please ask your prof or whatever you have at hand or give my some reasons of a reliable source why it is not.