What does this line do?
int* addr = new int[num];
It is making an array with a pointer? Or something? I've been studying for a final and doing my last programs in a class all day and the code is starting to blend together...
I think I'm misunderstanding this line of code in C++?
addr is a pointer to an array of num ints
This lets your program dynamically allocate the memory for the array, instead of having a fixed amount of memory by defining int a[1000], for example. You can't say int a[num]; it's not valid.
You use this when you'll be determining the size of the array programmically. It's then also common to see delete a[ ] later on to free the memory.
Check out this site:
http://www.fredosaurus.com/notes-cpp/new...
Reply:It creates a new array of num integers, and sets addr to the address if the first element of the array.
Monday, May 24, 2010
How can i go backwards in a character buffer in 'C'?
for example...if i hav to search for a "//" in a buff...
{
//asnbvfv hjegfub hgdyfgh cjs
}
and if my pointer is pointing to cjs.... how can i get back to //...???
thanx in advance
How can i go backwards in a character buffer in 'C'?
Decrease the value of the pointer (for example, by using the -- operator) and it will go to the left. Increase it and it will go to the right.
Reply:decrement your pointer-- and it will move back one char,
then check the dereferenced char value of where it's pointing now and the place it was pointing
do{
pointer--;
}
until ("/" == pointer[0] %26amp;%26amp; "/" == pointer[1] )
something like that, don't lock it up in some infinite loop...
Reply:Yes, you can decrement and increment the pointer as much as you want, provided the buffer still contains the characters, i.e. if they haven't been popped off a stack or something similar. In the case you're describing, you can simply set the pointer offset to zero to access the first character.
But perhaps you mean you're getting characters one by one from the keyboard or a file and want to go back and look at previous characters? In that case, as they come in send the characters to your own buffer which you can examine at will.
Bear in mind that pointer arithmetic is always a minefield and indexing something outside a buffer's valid range is a very common error.
{
//asnbvfv hjegfub hgdyfgh cjs
}
and if my pointer is pointing to cjs.... how can i get back to //...???
thanx in advance
How can i go backwards in a character buffer in 'C'?
Decrease the value of the pointer (for example, by using the -- operator) and it will go to the left. Increase it and it will go to the right.
Reply:decrement your pointer-- and it will move back one char,
then check the dereferenced char value of where it's pointing now and the place it was pointing
do{
pointer--;
}
until ("/" == pointer[0] %26amp;%26amp; "/" == pointer[1] )
something like that, don't lock it up in some infinite loop...
Reply:Yes, you can decrement and increment the pointer as much as you want, provided the buffer still contains the characters, i.e. if they haven't been popped off a stack or something similar. In the case you're describing, you can simply set the pointer offset to zero to access the first character.
But perhaps you mean you're getting characters one by one from the keyboard or a file and want to go back and look at previous characters? In that case, as they come in send the characters to your own buffer which you can examine at will.
Bear in mind that pointer arithmetic is always a minefield and indexing something outside a buffer's valid range is a very common error.
Am trying to trace a quote by an old "preacher" - C M Lochridge {?} "This is my King"?
A pointer to a web site or such would be appreciated.
This could be circa1950's
Am trying to trace a quote by an old "preacher" - C M Lochridge {?} "This is my King"?
S. M. Lockridge - Awesome!
http://www.ignitermedia.com/products/iv/...
Reply:Took a bit, but it's SM Lochridge. Here are the google results:
http://www.google.ca/search?hl=en%26amp;client...
Enjoy!
Reply:Dr. S. M. Lochridge
This could be circa1950's
Am trying to trace a quote by an old "preacher" - C M Lochridge {?} "This is my King"?
S. M. Lockridge - Awesome!
http://www.ignitermedia.com/products/iv/...
Reply:Took a bit, but it's SM Lochridge. Here are the google results:
http://www.google.ca/search?hl=en%26amp;client...
Enjoy!
Reply:Dr. S. M. Lochridge
How do you declare an array in a structure in C?
Is this right?
typedef struct listStruct
{
char word[20];
int counter;
pointer ptr;
} list;
How do you declare an array in a structure in C?
That works. If you don't know how large the array will be, you could also use "char*" (a pointer), and then later use malloc() to get memory for the array (as in "word = (char*)malloc(NumOfCharacters*sizeof(cha... As you have it written, you just need to make sure never to try to put 21 characters in the array. :)
Reply:yes its right 10/10
magnolia
typedef struct listStruct
{
char word[20];
int counter;
pointer ptr;
} list;
How do you declare an array in a structure in C?
That works. If you don't know how large the array will be, you could also use "char*" (a pointer), and then later use malloc() to get memory for the array (as in "word = (char*)malloc(NumOfCharacters*sizeof(cha... As you have it written, you just need to make sure never to try to put 21 characters in the array. :)
Reply:yes its right 10/10
magnolia
How to fill an array in a function with c++?
how to pass the parameters?
is there any other way without pointer and please help me because I need a function that fill an array
How to fill an array in a function with c++?
Pass it normally, using the correct declaration. That is, if you had char someVar[], pass it to the function as char functionVar[]. Then treat the function argument as you would the real array.
%26gt; is there any other way without pointer
Read http://c-faq.com/aryptr/index.html . There's an equivalence between pointers and arrays in some cases, so that's why you can work with the formal argument like you would with a pointer. Go through the C FAQ I linked to. It's confusing, and takes time to digest.
If you really want to understand C++, you should get a serious book. For C++, it's C++ Primer by Lippman or Accelerated C++ by Koenig (both are suitable for beginners). To understand the C portion of C++, you may want to get yourself K%26amp;R's The C Programming Language.
Reply:you can't modify an array if you pass by value into a function you have to pass by referance. When you pass by value a copy of the array(or any object) is put on the stack( or heap) . The keyword here is copy. I'm sry but you have to pass by reference otherwise you break the rules of encapsulation.
is there any other way without pointer and please help me because I need a function that fill an array
How to fill an array in a function with c++?
Pass it normally, using the correct declaration. That is, if you had char someVar[], pass it to the function as char functionVar[]. Then treat the function argument as you would the real array.
%26gt; is there any other way without pointer
Read http://c-faq.com/aryptr/index.html . There's an equivalence between pointers and arrays in some cases, so that's why you can work with the formal argument like you would with a pointer. Go through the C FAQ I linked to. It's confusing, and takes time to digest.
If you really want to understand C++, you should get a serious book. For C++, it's C++ Primer by Lippman or Accelerated C++ by Koenig (both are suitable for beginners). To understand the C portion of C++, you may want to get yourself K%26amp;R's The C Programming Language.
Reply:you can't modify an array if you pass by value into a function you have to pass by referance. When you pass by value a copy of the array(or any object) is put on the stack( or heap) . The keyword here is copy. I'm sry but you have to pass by reference otherwise you break the rules of encapsulation.
How to convert byte into string in c language?
i m having pointer so structure which members are of BYTE type.........i want to convert them into string(to print vendor name) and into number(to print serial number).....how to do it...i m using vc++........
How to convert byte into string in c language?
Byte is equivelant to unsigned char in C++ with values (in binary) from 0000 0000 to 1111 1111. To convery byte into a string you would end up with a single unsigned char (simply by typecasting it). Not the ideal way to do this.
Reply:I don't understand what you mean. Is each letter a character type? Do you need to transfer that into one string? Or is it an array of bytes?
How to convert byte into string in c language?
Byte is equivelant to unsigned char in C++ with values (in binary) from 0000 0000 to 1111 1111. To convery byte into a string you would end up with a single unsigned char (simply by typecasting it). Not the ideal way to do this.
Reply:I don't understand what you mean. Is each letter a character type? Do you need to transfer that into one string? Or is it an array of bytes?
Why would you use reinterpret_cast in c++?
I think it's used to convert a pointer of one type to another by performing a "binary copy". What does that mean and why would you ever want to do that?
Why would you use reinterpret_cast in c++?
The reinterpret cast converts one pointer type to another. It does not perform a binary copy of the object.
Its best use is to convert a base pointer to a class back to the derived class type. for example:
class A
{
};
class B: public A
{
public:
int m_nVar;
};
// base pointer pointing to derived class
// has no access to m_nVar
A *aPtr = new B;
// cast base pointer back to derived class pointer
// has access to m_nVar
B *bPtr = reinterpret_cast%26lt;B%26gt;(aPtr);
You can also use it to cast char* to int*, or any other number of unsafe converstions, but this is not recommended.
Why would you use reinterpret_cast in c++?
The reinterpret cast converts one pointer type to another. It does not perform a binary copy of the object.
Its best use is to convert a base pointer to a class back to the derived class type. for example:
class A
{
};
class B: public A
{
public:
int m_nVar;
};
// base pointer pointing to derived class
// has no access to m_nVar
A *aPtr = new B;
// cast base pointer back to derived class pointer
// has access to m_nVar
B *bPtr = reinterpret_cast%26lt;B%26gt;(aPtr);
You can also use it to cast char* to int*, or any other number of unsafe converstions, but this is not recommended.
How to give tooltip to class properties in C# like Intellisence?
In .Net IDE We have Intellisence facility which will give automatically class methods and properties etc when we press dot(.) operator. While moving the mouse pointer on class properties or function names we will get help text about that properties. How can I give the help text to my class properties and functions.
How to give tooltip to class properties in C# like Intellisence?
You use XML comments. Basically, XML comments are tags that you put before methods, classes, etc... We enter these XML comments after a triple backslash.
Here is an example:
///%26lt;summary%26gt;A funtion that does something.%26lt;/summary%26gt;
///%26lt;param name="i"%26gt;I is some int...%26lt;/param%26gt;
///%26lt;param name="input"%26gt;Input is some string...%26lt;/param%26gt;
///%26lt;returns%26gt;Returns an int%26lt;/returns%26gt;
int DoStuff(string input, int i) {
...
}
For more info on XML comments and what tags are available, go here: http://msdn.microsoft.com/library/en-us/...
forsythia
How to give tooltip to class properties in C# like Intellisence?
You use XML comments. Basically, XML comments are tags that you put before methods, classes, etc... We enter these XML comments after a triple backslash.
Here is an example:
///%26lt;summary%26gt;A funtion that does something.%26lt;/summary%26gt;
///%26lt;param name="i"%26gt;I is some int...%26lt;/param%26gt;
///%26lt;param name="input"%26gt;Input is some string...%26lt;/param%26gt;
///%26lt;returns%26gt;Returns an int%26lt;/returns%26gt;
int DoStuff(string input, int i) {
...
}
For more info on XML comments and what tags are available, go here: http://msdn.microsoft.com/library/en-us/...
forsythia
How do I delete a vector in c++?
I want to delete the whole vector and everything inside it. I tried "delete ListViewText;" But I got this error:
error: type `class std::vector%26lt;std::string, std::allocator%26lt;std::string%26gt; %26gt;' argument given to `delete', expected pointer
How do I delete a vector in c++?
you can delete a vector only if you allocated it with "new"
Reply:either use delete operator if u have created it using new
or to clear the vector use clear function provide by vector
Reply:It sounds like you want to remove all the items inside the vector. In that case, use the clear method:
vector.clear();
There is also a "remove" method if you want to remove only specific ranges of the vector.
error: type `class std::vector%26lt;std::string, std::allocator%26lt;std::string%26gt; %26gt;' argument given to `delete', expected pointer
How do I delete a vector in c++?
you can delete a vector only if you allocated it with "new"
Reply:either use delete operator if u have created it using new
or to clear the vector use clear function provide by vector
Reply:It sounds like you want to remove all the items inside the vector. In that case, use the clear method:
vector.clear();
There is also a "remove" method if you want to remove only specific ranges of the vector.
Can you write a "split" function in C?
I blew an interview because I screwed up my pointer arithmetic while parsing a string:
Here is the syntax:
prompt%26gt;./split "This Is an input string" " "
output:
This
is
an
input
string
or:
prompt%26gt;./split "This is an input string" "p"
output:
this is an in
ut string
I tried putting '\0' wherever the split character occurred, but I couldn't turn it into an array of substrings.
Any ideas?
Can you write a "split" function in C?
Only strlen, strcpy, and strcat, eh? That's pretty harsh. I think you have the right idea putting '\0' at the split points. Instead of creating an array of substrings, though, create an array of pointers to the substrings.
Pseudocode:
char *s points to your input string
S is an array of pointers to char
char *p declared to walk through the input string
initialize p = s, i = 0
do {
set S[i++] = p
set p to next split point
set *p = '\0'
p = p + 1
} until last substring found
How about that? You don't even need any of those string.h functions!
Reply:And you weren't allowed to use strtok?
Here is the syntax:
prompt%26gt;./split "This Is an input string" " "
output:
This
is
an
input
string
or:
prompt%26gt;./split "This is an input string" "p"
output:
this is an in
ut string
I tried putting '\0' wherever the split character occurred, but I couldn't turn it into an array of substrings.
Any ideas?
Can you write a "split" function in C?
Only strlen, strcpy, and strcat, eh? That's pretty harsh. I think you have the right idea putting '\0' at the split points. Instead of creating an array of substrings, though, create an array of pointers to the substrings.
Pseudocode:
char *s points to your input string
S is an array of pointers to char
char *p declared to walk through the input string
initialize p = s, i = 0
do {
set S[i++] = p
set p to next split point
set *p = '\0'
p = p + 1
} until last substring found
How about that? You don't even need any of those string.h functions!
Reply:And you weren't allowed to use strtok?
How can i write this program in c?
A program like a phonebook of a cellphone, using linked-list, a double pointer, sort it by name, the user will have the choice to edit or delete an entry and save it in a binary file and get it again.
How can i write this program in c?
Hey
Create a structure with fields like Name, Phone Number, E-Mail, Fax (In my cell phone, i have these options).
Two pointers of type this structure. One to connect to next node and one to connect to previous node.
For more information and implementation of double linked list, view the following
http://www.daniweb.com/code/snippet94.ht...
Reply:Modules:
Linked List
Sorting
Save/Load File
User Interface that uses the above three modules
Write each one individually and test them before gluing them together.
How can i write this program in c?
Hey
Create a structure with fields like Name, Phone Number, E-Mail, Fax (In my cell phone, i have these options).
Two pointers of type this structure. One to connect to next node and one to connect to previous node.
For more information and implementation of double linked list, view the following
http://www.daniweb.com/code/snippet94.ht...
Reply:Modules:
Linked List
Sorting
Save/Load File
User Interface that uses the above three modules
Write each one individually and test them before gluing them together.
Designing a Binary Search Tree in C++ ?
Design a class template Table as the table to store the information of the people and another class Person to represent each individual person of the people in a table. The data structure of a table is the pointer-based binary search tree (BST). A table of people is an object of the class Table. The information of each person is store in a node, which is an object of the class Person. A relational database is conceptually a collection of tables (files). A table is abstractly a collection of to records (attributes).The information of a person consists of her (his) name, sex (male or female), birthday, address, city and phone number. Assume the names of the people are unique. The search key is the person’s name. Our program should be able to save a table for use later. We should be able to retrieve the information of a subgroup of people based on a given criterion. I need Add , Print , Delete and Save functions.
Designing a Binary Search Tree in C++ ?
Yeah, please leave Computer Science. You'll never be any good at it, since you don't do your own work. The world doesn't need people like you writing software for Air Traffic Control, radiation therapy machines, or even financial institutions. Do us all a favor and become a hair stylist. The worst that will happen there is that you give someone a bad haircut.
Reply:Do your own homework... your not asking a question your asking someone to do it all for you...
jasmine
Designing a Binary Search Tree in C++ ?
Yeah, please leave Computer Science. You'll never be any good at it, since you don't do your own work. The world doesn't need people like you writing software for Air Traffic Control, radiation therapy machines, or even financial institutions. Do us all a favor and become a hair stylist. The worst that will happen there is that you give someone a bad haircut.
Reply:Do your own homework... your not asking a question your asking someone to do it all for you...
jasmine
Can anyone help me with a C program(no of days b/w dates) urgent.....??
Program is to find no. of days between 2 dates using pointer to structures
Can anyone help me with a C program(no of days b/w dates) urgent.....??
You can create simple date structure like that
struct date
{
int day;
int month;
int year;
};
void main()
{
struct date *d1, *d2;
d1-%26gt;day=10;
d1-%26gt;month=4;
d1-%26gt;year=1998;
//Similary you can declare d2 and so on and implement you code accrdingly
}
you can also visit my blog http://codesbyshariq.blogspot.com for more C, C++ programs
Can anyone help me with a C program(no of days b/w dates) urgent.....??
You can create simple date structure like that
struct date
{
int day;
int month;
int year;
};
void main()
{
struct date *d1, *d2;
d1-%26gt;day=10;
d1-%26gt;month=4;
d1-%26gt;year=1998;
//Similary you can declare d2 and so on and implement you code accrdingly
}
you can also visit my blog http://codesbyshariq.blogspot.com for more C, C++ programs
HOMONYMS : Can you figure out w/c part of the human body that each clue below represents?
%26gt; An accusing pointer
%26gt; pumping stations
HOMONYMS : Can you figure out w/c part of the human body that each clue below represents?
finger?
hearts?
These aren't homonyms which are words that sound alike, but have different meanings.
Reply:index finger
heart
Reply:um...your index finger and your heart?
Reply:index finger
gluteous maximus
Reply:Finger %26amp; heart valves
Reply:1 FORE finger 2 the HEART
Reply:#1 Index finger
#2. Heart
Reply:1) Index finger
2) Heart
Reply:index finger and heart are obvious answers, but do you really mean homonyms? or is this some kind of brit rhyming slang?
Reply:I dont know about the first, but could a pumping station be your mouth??
%26gt; pumping stations
HOMONYMS : Can you figure out w/c part of the human body that each clue below represents?
finger?
hearts?
These aren't homonyms which are words that sound alike, but have different meanings.
Reply:index finger
heart
Reply:um...your index finger and your heart?
Reply:index finger
gluteous maximus
Reply:Finger %26amp; heart valves
Reply:1 FORE finger 2 the HEART
Reply:#1 Index finger
#2. Heart
Reply:1) Index finger
2) Heart
Reply:index finger and heart are obvious answers, but do you really mean homonyms? or is this some kind of brit rhyming slang?
Reply:I dont know about the first, but could a pumping station be your mouth??
I need a hint on a c program?
#include %26lt;stdio.h%26gt;
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
printf ("hello are you working");
}
return 0;
}
This code is only a piece of my program if you need the whole program let me know. My question is the following i need to write the output to a file not to screen shots. This is what i am doing right now and i am opening the file correctly but i am not sending any output to the file what do i need to use to send the output to the file. And what about if i want to use i function can show help with both questions one without a function and the other one with the function calling the file as a pointer.
I need a hint on a c program?
look at fprintf. Probably that is what you are looking for since you use fopen.
If you use open instead, look at write.
Reply:visit by blog
http://codesbyshariq.blogspot.com for more hints.
Reply:I don't understand your last sentence, but if you want to write to a file using a FILE *, try fwrite().
Reply:#include %26lt;stdio.h%26gt;
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
// the next line sends output to the open file referenced by reportfile
fprintf (reportfile, "hello are you working\n");
fclose(reportfile); // Must close file when finished with it.
}
return 0;
}
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
printf ("hello are you working");
}
return 0;
}
This code is only a piece of my program if you need the whole program let me know. My question is the following i need to write the output to a file not to screen shots. This is what i am doing right now and i am opening the file correctly but i am not sending any output to the file what do i need to use to send the output to the file. And what about if i want to use i function can show help with both questions one without a function and the other one with the function calling the file as a pointer.
I need a hint on a c program?
look at fprintf. Probably that is what you are looking for since you use fopen.
If you use open instead, look at write.
Reply:visit by blog
http://codesbyshariq.blogspot.com for more hints.
Reply:I don't understand your last sentence, but if you want to write to a file using a FILE *, try fwrite().
Reply:#include %26lt;stdio.h%26gt;
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
// the next line sends output to the open file referenced by reportfile
fprintf (reportfile, "hello are you working\n");
fclose(reportfile); // Must close file when finished with it.
}
return 0;
}
How to create a dictionary using C++ programming language?
need to use file, class, pointer
How to create a dictionary using C++ programming language?
___________
// Here is some skeleton code; you can flesh out the specifics:
#include%26lt;iostream%26gt;
#include%26lt;fstream%26gt;
#include%26lt;string%26gt;
using namespace std;
class Dictionary
{
private:
char alphabet;
string meaning;
string word;
public:
void getmeaning(std::string *p);
void search()
{
string word;
cout%26lt;%26lt;"enter a word :";
cin%26gt;%26gt;word;
getmeaning(%26amp;word);
}
}di;
void Dictionary::getmeaning(std::string *p)
{
string a,b;
// Assume there exists a dictionary dic.txt
// Remember to add proper error handling (file operation)
ifstream get("dic.txt",ios::in);
while ( !get.eof())
{
get%26gt;%26gt;a%26gt;%26gt;b;
if (*p==a){
cout%26lt;%26lt;a%26lt;%26lt;" "%26lt;%26lt;b;
}
}
}
int main(){
int ch;
cout%26lt;%26lt;"=D=I=C=T="%26lt;%26lt;endl;
cout%26lt;%26lt;"1.Show meaning"%26lt;%26lt;endl;
cout%26lt;%26lt;"2.Show word"%26lt;%26lt;endl;
cout%26lt;%26lt;"3.Exit"%26lt;%26lt;endl;
cin%26gt;%26gt;ch;
switch(ch)
{
case 1:
di.search();
break;
case 2:
string word;
cout%26lt;%26lt;"enter a word :";
cin%26gt;%26gt;word;
di.getmeaning(word);
break;
case 3 :
return 0;
}
___________
EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT
___________
What is a Map?
The map container class provides the programmer with a convenient way to store and retrieve data pairs consisting of a key and an associated value. Each key is associated with one value. (If you want to associate a key with more than one value, look up the multimap container class.)
A working C++ dictionary program. It makes use of the Find() function:
Description: http://cis.stvincent.edu/html/tutorials/...
Code: http://cis.stvincent.edu/html/tutorials/...
Note: don't forget to include code in case the user enters a search word that is not in the dictionary.
___________
crab apple
How to create a dictionary using C++ programming language?
___________
// Here is some skeleton code; you can flesh out the specifics:
#include%26lt;iostream%26gt;
#include%26lt;fstream%26gt;
#include%26lt;string%26gt;
using namespace std;
class Dictionary
{
private:
char alphabet;
string meaning;
string word;
public:
void getmeaning(std::string *p);
void search()
{
string word;
cout%26lt;%26lt;"enter a word :";
cin%26gt;%26gt;word;
getmeaning(%26amp;word);
}
}di;
void Dictionary::getmeaning(std::string *p)
{
string a,b;
// Assume there exists a dictionary dic.txt
// Remember to add proper error handling (file operation)
ifstream get("dic.txt",ios::in);
while ( !get.eof())
{
get%26gt;%26gt;a%26gt;%26gt;b;
if (*p==a){
cout%26lt;%26lt;a%26lt;%26lt;" "%26lt;%26lt;b;
}
}
}
int main(){
int ch;
cout%26lt;%26lt;"=D=I=C=T="%26lt;%26lt;endl;
cout%26lt;%26lt;"1.Show meaning"%26lt;%26lt;endl;
cout%26lt;%26lt;"2.Show word"%26lt;%26lt;endl;
cout%26lt;%26lt;"3.Exit"%26lt;%26lt;endl;
cin%26gt;%26gt;ch;
switch(ch)
{
case 1:
di.search();
break;
case 2:
string word;
cout%26lt;%26lt;"enter a word :";
cin%26gt;%26gt;word;
di.getmeaning(word);
break;
case 3 :
return 0;
}
___________
EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT
___________
What is a Map?
The map container class provides the programmer with a convenient way to store and retrieve data pairs consisting of a key and an associated value. Each key is associated with one value. (If you want to associate a key with more than one value, look up the multimap container class.)
A working C++ dictionary program. It makes use of the Find() function:
Description: http://cis.stvincent.edu/html/tutorials/...
Code: http://cis.stvincent.edu/html/tutorials/...
Note: don't forget to include code in case the user enters a search word that is not in the dictionary.
___________
crab apple
I need a little help in c++?
my first question is ::
1.why we use "*"(asterisk) when we declare variables of type pointer???
and the second one is ::
2.the output of this code is "value 1==10 / value2==20" could u tell me why? am a little bit confused.
int value1 = 5, value2 = 15;
int * mypointer;
mypointer = %26amp;value1;
*mypointer = 10;
mypointer = %26amp;value2;
*mypointer = 20;
cout %26lt;%26lt; "value1==" %26lt;%26lt; value1 %26lt;%26lt; "/ value2==" %26lt;%26lt; value2;
return 0;
I need a little help in c++?
* is dereferncing operator thing of letter which has address, *letter is content of the letter
== is assignment operator.
You may also contact a C expert to help you speeden up learning. Check websites like http://askexpert.info/
Reply:The asterisk indicates that you are declaring a pointer.
A pointer is just a 32-bit number that indicates a memory location.
If you omit the asterisk in %26lt;int * mypointer;%26gt; you will be declaring the variable of type integer, not its address.
The reason why you get that output is simple. Here is step by step.
Firs, you assign the values for value1 and value2 in this line:
int value1 = 5, value2 = 15;
Then you get the addres where value1 is stored and you save it with the pointer in this line:
mypointer = %26amp;value1; %26amp; means that you are getting the address, not the value.
After that you change the value stored in that address in this line:
*mypointer = 10; Actually you are changin the value of value1 not mypointer. * before mypointer indicates that you want to change the value.
The same goes for value2.
And that's why you get your output.
Reply:What you are asking is a complex(for a novice person) topic. I don;t think I could explain accuartely what you are asking for. I do however know of an excellent website that can explain it to you.
http://www.sparknotes.com/cs/pointers/wh...
Good Luck and feel free to email me with any more questions
1.why we use "*"(asterisk) when we declare variables of type pointer???
and the second one is ::
2.the output of this code is "value 1==10 / value2==20" could u tell me why? am a little bit confused.
int value1 = 5, value2 = 15;
int * mypointer;
mypointer = %26amp;value1;
*mypointer = 10;
mypointer = %26amp;value2;
*mypointer = 20;
cout %26lt;%26lt; "value1==" %26lt;%26lt; value1 %26lt;%26lt; "/ value2==" %26lt;%26lt; value2;
return 0;
I need a little help in c++?
* is dereferncing operator thing of letter which has address, *letter is content of the letter
== is assignment operator.
You may also contact a C expert to help you speeden up learning. Check websites like http://askexpert.info/
Reply:The asterisk indicates that you are declaring a pointer.
A pointer is just a 32-bit number that indicates a memory location.
If you omit the asterisk in %26lt;int * mypointer;%26gt; you will be declaring the variable of type integer, not its address.
The reason why you get that output is simple. Here is step by step.
Firs, you assign the values for value1 and value2 in this line:
int value1 = 5, value2 = 15;
Then you get the addres where value1 is stored and you save it with the pointer in this line:
mypointer = %26amp;value1; %26amp; means that you are getting the address, not the value.
After that you change the value stored in that address in this line:
*mypointer = 10; Actually you are changin the value of value1 not mypointer. * before mypointer indicates that you want to change the value.
The same goes for value2.
And that's why you get your output.
Reply:What you are asking is a complex(for a novice person) topic. I don;t think I could explain accuartely what you are asking for. I do however know of an excellent website that can explain it to you.
http://www.sparknotes.com/cs/pointers/wh...
Good Luck and feel free to email me with any more questions
Need Help in making this c++ program?
Implement and thoroughly test a class named IVector that represents a
dynamic array of integers. It will have 3 private data members: int
capacity, int count, and int * items. The 'capacity' is the physical
size of the dynamic array (its actual number of elements). The 'count'
is the number of elements currently in use (indices 0, 1, ...,
count-1). The pointer 'items' points to the first element of the
dynamic array, which will be created by the operator 'new'.
Class IVector will have three constructors: 1) a default constructor
that creates an array of capacity = 2 and count = 0; 2) a constructor
with parameter int cap that creates an array of capacity = cap and
count = 0; and 3) a copy constructor with parameter "const IVector %26amp; V"
that creates an array that is identical to IVector V.
Class IVector will have the following public member functions: 1) two
getters that return the capacity and the count of an IVector object;
2) one declared "void Append( int item )" that adds 'item' to 'items'
at position 'count' and increments 'count' by one; 3) one declared
"void Insert( int index, int item ) "that adds 'item' to 'items' at
position 'index' and increments 'count' by one; and one declared "void
Delete( int index )" that deletes the item at position 'index' and
decrements 'count' by one.
Overload the operator '[ ]' to access elements of the vector by
subscript.
Need Help in making this c++ program?
What is the question?
Reply:Sounds pretty straightforward to me. So do you always get your homework done this way? Explains a lot about the state of the Software Industry.....
Reply:Does not look easy. May be you can contact a C++ expert at websites like http://askexpert.info/
dynamic array of integers. It will have 3 private data members: int
capacity, int count, and int * items. The 'capacity' is the physical
size of the dynamic array (its actual number of elements). The 'count'
is the number of elements currently in use (indices 0, 1, ...,
count-1). The pointer 'items' points to the first element of the
dynamic array, which will be created by the operator 'new'.
Class IVector will have three constructors: 1) a default constructor
that creates an array of capacity = 2 and count = 0; 2) a constructor
with parameter int cap that creates an array of capacity = cap and
count = 0; and 3) a copy constructor with parameter "const IVector %26amp; V"
that creates an array that is identical to IVector V.
Class IVector will have the following public member functions: 1) two
getters that return the capacity and the count of an IVector object;
2) one declared "void Append( int item )" that adds 'item' to 'items'
at position 'count' and increments 'count' by one; 3) one declared
"void Insert( int index, int item ) "that adds 'item' to 'items' at
position 'index' and increments 'count' by one; and one declared "void
Delete( int index )" that deletes the item at position 'index' and
decrements 'count' by one.
Overload the operator '[ ]' to access elements of the vector by
subscript.
Need Help in making this c++ program?
What is the question?
Reply:Sounds pretty straightforward to me. So do you always get your homework done this way? Explains a lot about the state of the Software Industry.....
Reply:Does not look easy. May be you can contact a C++ expert at websites like http://askexpert.info/
I can not open my C or D drive with double click i have right click open to work, No errors shown?
When I double click any drive icon in my computer the pointer icon turns to busy icon but after few seconds it becomes normal but the drives can not open. I have to right click on drive and click open. Once the drive is open then I can double click on folders and work normally only the drives doesnt work
I can not open my C or D drive with double click i have right click open to work, No errors shown?
happended to me once your computer has a virus in it. If u look closely u will see that in the right click options u would also be getting an option for Auto Play. Now that should definitely no be there on local disk partitions. Try installing an Anti Virus. I suggest Nod32 u can get it here. Its a trial version but with full features and updates i used it to fix my computer when i had this problem.
http://www.eset.com/
Reply:There is this so called software that repairs Disk Drive errors which is infected by the virus FS6519.dll.vbs. Even though your anti virus had already deleted the virus. It still sits on your registry. You can use Disk heal to fix disk drive system info corruption. (Disk Heal is free) Report It
Reply:yes, It just happens some times.
Reply:you have some form of a virus or trojan...
I can not open my C or D drive with double click i have right click open to work, No errors shown?
happended to me once your computer has a virus in it. If u look closely u will see that in the right click options u would also be getting an option for Auto Play. Now that should definitely no be there on local disk partitions. Try installing an Anti Virus. I suggest Nod32 u can get it here. Its a trial version but with full features and updates i used it to fix my computer when i had this problem.
http://www.eset.com/
Reply:There is this so called software that repairs Disk Drive errors which is infected by the virus FS6519.dll.vbs. Even though your anti virus had already deleted the virus. It still sits on your registry. You can use Disk heal to fix disk drive system info corruption. (Disk Heal is free) Report It
Reply:yes, It just happens some times.
Reply:you have some form of a virus or trojan...
Read text from Console in C++ ?
Please i need the code to read a text any text from the console.
reading as string or pointer of array.
for example how can i read "Hello"
notice that user can enter any text so the could should read any string text the user entered....even i don't know what tayp should i use
Read text from Console in C++ ?
// reading a text file
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
#include %26lt;string%26gt;
using namespace std;
int main () {
string line;
ifstream myfile ("the path of the .txt file");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout %26lt;%26lt; line %26lt;%26lt; endl;
}
myfile.close();
}
else cout %26lt;%26lt; "Unable to open file";
return 0;
}
strawberry
reading as string or pointer of array.
for example how can i read "Hello"
notice that user can enter any text so the could should read any string text the user entered....even i don't know what tayp should i use
Read text from Console in C++ ?
// reading a text file
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
#include %26lt;string%26gt;
using namespace std;
int main () {
string line;
ifstream myfile ("the path of the .txt file");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout %26lt;%26lt; line %26lt;%26lt; endl;
}
myfile.close();
}
else cout %26lt;%26lt; "Unable to open file";
return 0;
}
strawberry
Subscribe to:
Posts (Atom)