hi...we need to create a linked list of structures(nodes) using pointers ..the problem when i allocate a place for every new node it gives an error :
#include%26lt;stdio.h%26gt;
struct node{
char name[20];
struct node *next;
};
int main(void){
struct node *p;
//we want to create 3 nodes
for(int i=0;i%26lt;3;i++)
{
p = new node; //AND HERE IT GIVES THE ERROR ('new' undeclared identifier)
so whats the problem ?any help is appreciated
Help in c language.data structure ?
Change the struct as follows:
#define NAME_SIZE 20
struct node{
char name[NAME_SIZE];
struct node *next;
};
int main(void){
struct node *top = NULL;
struct node *newnode;
//we want to create 3 nodes
char buf[256];
for(int i=0;i%26lt;3;i++)
{
newnode = makeNode();
sprintf(buf, "Node # %d", i); /* make a node name */
setName(newnode, buf);
if ( top != NULL) newnode-%26gt;next = top;
top = newnode;
}
}
/* create a function make a node */
struct node * makeNode()
{
p = (node*)malloc(sizeof(node));
/* remember to initialize the node name */
p-%26gt;name[0] = '\0';
p-%26gt;next = NULL;
return p;
}
/* create a function to set the name
* this makes sure that you dont put in a string
* that is too long and overwrite memory.
*/
void setName(struct node * p, char * name)
{
strncpy(p-%26gt;name, name, NAME_SIZE);
/* null terminate the string */
p-%26gt;name[NAME_SIZE-1] = '\0';
}
Reply:"new" is a C++ operator, use malloc for C:
p = (node*)malloc(sizeof(node));
Reply:I think in c you need to do something like:
p = (node*)malloc(sizeof(node));
instead of p = new node;
you may want to check if your struct format is correct as well
survey software
Monday, May 24, 2010
In C++, What is the use of using std::ios? What will it do in the program?
I also want to know the use of
using std::setiosflags
and
using std::fixed
Can u give examples for all
Explain pointers in simple and complete way...
Can u explain how to use strings...especially when the
program is in class format?
Thanks
In C++, What is the use of using std::ios? What will it do in the program?
Please do your school questions alone otherwise you will not learn. I am sure that your C++ book explains all these if only you did care to read it.
Reply:.... "and then, could you write a research paper for me on the rise of computing in the 20th century. Also, explain, in mind-boggling detail, the entire concept of object oriented programming. Can u give an exhaustive explanation of all the different data types, as well as complete programs that use them....."
Ok - I'm on it!
Reply:Even worse Old Programmers like me will never hire you.
using std::setiosflags
and
using std::fixed
Can u give examples for all
Explain pointers in simple and complete way...
Can u explain how to use strings...especially when the
program is in class format?
Thanks
In C++, What is the use of using std::ios? What will it do in the program?
Please do your school questions alone otherwise you will not learn. I am sure that your C++ book explains all these if only you did care to read it.
Reply:.... "and then, could you write a research paper for me on the rise of computing in the 20th century. Also, explain, in mind-boggling detail, the entire concept of object oriented programming. Can u give an exhaustive explanation of all the different data types, as well as complete programs that use them....."
Ok - I'm on it!
Reply:Even worse Old Programmers like me will never hire you.
In c++, how would u delete a node from a linked list?
ok so im supposed to delete a user specified node from a list of 10 nodes. I can locate the node but how would i actually delete it? I like dymanic arrays but sometimes r a pain cause of pointers :(
In c++, how would u delete a node from a linked list?
In general you will
1. Point the previous node at the next node
2. If it's a doubly linked list point the next node at the previous node
3. Destroy the current node, being sure to delete and release all allocated memory.
This site provides more detail:
http://www.inversereality.org/tutorials/...
In c++, how would u delete a node from a linked list?
In general you will
1. Point the previous node at the next node
2. If it's a doubly linked list point the next node at the previous node
3. Destroy the current node, being sure to delete and release all allocated memory.
This site provides more detail:
http://www.inversereality.org/tutorials/...
C++ programming help?
Write a program that uses a random number generator to create sentences. The program should use four arrays of pointers to char called article[], noun[], verb[], and preposition[]. The program should create a sentence by selecting a word at random from each of the arrays in the following order: article[], noun[], verb[], preposition[], article[], noun[]. As each word is picked, it should be concatenated to the previous words in an array which is large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period.
The arrays should be filled as follows: article[] should contain "the", "a", "one", "some", and "any"; noun[] should contain "boy", "girl", "dog", "town", and "car"; verb[] should contain "drove", "jumped", "ran", "walked", and "skipped"; and preposition[] should contain "to", "from", "over", "under", and "on".
i just need started
C++ programming help?
gr8 question dude,but y do u thnk dat someones going to waste so much time and energy doing dat.u shud consult some professional guy ,here
The arrays should be filled as follows: article[] should contain "the", "a", "one", "some", and "any"; noun[] should contain "boy", "girl", "dog", "town", and "car"; verb[] should contain "drove", "jumped", "ran", "walked", and "skipped"; and preposition[] should contain "to", "from", "over", "under", and "on".
i just need started
C++ programming help?
gr8 question dude,but y do u thnk dat someones going to waste so much time and energy doing dat.u shud consult some professional guy ,here
Need help with a turbo C program?
Well you see I am trying to make a program with pointers in which it counts the number of occurrences of any two vowels in succession in a line of text by using pointers.For example
"Please read this application and give me gratuity". Such occurences are ea,ea,ui.
And in case anyone knows from where this program has been taken,please do tell:)
Need help with a turbo C program?
You didn't explain whether u wanted 'aaee' to be counted as 2 or 3. I assume it to be 3 as aa,ae,ee. The code assuming this is:
#include%26lt;stdio.h%26gt;
#include%26lt;string.h%26gt;
int isVowel(char a)
{
if(a%26gt;64%26amp;%26amp;a%26lt;91)
a+=32;
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u...
return 1;
else return 0;
}
int main()
{
char *a="Please read this application and give me gratuity";
int i=0, count=0;
while(a[i+1]!='\0')
{
if(isVowel(a[i])%26amp;%26amp;isVowel(a[i+1]))
{printf("Occurence no %d: %c%c",i+1,a[i],a[i+1]);
count++;}
i++;
}
printf("The desired count is %d", count);
return 0;
}
Reply:if you dont like programming and would rather cheat than even attempt it, drop the class or get a new major like English Lit :)
Reply:Please look at the comments. Try to follow the logic. Plug in a sample word or phrase. Notice how the program processes the input at each stage of its execution.
Note: Below, I did not know whether you want a user to input a string, or just program so that the line of text is directly assigned to a pointer:
char * copy_str = "Please read this application and give me gratuity"
I allowed for user input of text, which I assigned to a character array. I subsequently copied that array into a character pointer—for further processing.
If you wish, you can replace all code located between the two lines of asteriks (*'s) with the above * copy_str assignment statement. Simply place the assignment immediately above the While clause.
___________________________
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
int main()
{
int i;
int count = 0;
int singleVowel = 0;
/*************************************...
/* 50 is space enough for text and terminating character. */
char buffer[50];
printf("Enter a line of text: ");
fgets(buffer, sizeof(buffer), stdin);
/* Copy input into a character pointer for further processing. */
/* First, allocate memory; and, then do the copying. */
char * copy_str = malloc( strlen(buffer) + 1);
strcpy(copy_str, buffer);
/*************************************...
/* Now, lets iterate through each character in the string. */
while (*copy_str++ != '\0')
{
switch(*copy_str)
{
/* Check for a vowel. */
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
/* We have found a vowel; */
/* so, check to see if the preceding character was a vowel */
if (singleVowel = =1)
/* Increase the count of consecutive vowels */
count++;
else
/* Here, the preceding character was not a vowel */
/* If the next character is a vowel, */
/* then it will counts as being a consecutive vowel. */
singleVowel = 1;
default:
/* This particular character is not a vowel. */
/* So, any next vowel will not be a consecutive one */
singleVowel = 0;
}
}
printf("In text, we have %d consecutive vowels.\n", count);
return 0;
}
________________________
survey research
"Please read this application and give me gratuity". Such occurences are ea,ea,ui.
And in case anyone knows from where this program has been taken,please do tell:)
Need help with a turbo C program?
You didn't explain whether u wanted 'aaee' to be counted as 2 or 3. I assume it to be 3 as aa,ae,ee. The code assuming this is:
#include%26lt;stdio.h%26gt;
#include%26lt;string.h%26gt;
int isVowel(char a)
{
if(a%26gt;64%26amp;%26amp;a%26lt;91)
a+=32;
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u...
return 1;
else return 0;
}
int main()
{
char *a="Please read this application and give me gratuity";
int i=0, count=0;
while(a[i+1]!='\0')
{
if(isVowel(a[i])%26amp;%26amp;isVowel(a[i+1]))
{printf("Occurence no %d: %c%c",i+1,a[i],a[i+1]);
count++;}
i++;
}
printf("The desired count is %d", count);
return 0;
}
Reply:if you dont like programming and would rather cheat than even attempt it, drop the class or get a new major like English Lit :)
Reply:Please look at the comments. Try to follow the logic. Plug in a sample word or phrase. Notice how the program processes the input at each stage of its execution.
Note: Below, I did not know whether you want a user to input a string, or just program so that the line of text is directly assigned to a pointer:
char * copy_str = "Please read this application and give me gratuity"
I allowed for user input of text, which I assigned to a character array. I subsequently copied that array into a character pointer—for further processing.
If you wish, you can replace all code located between the two lines of asteriks (*'s) with the above * copy_str assignment statement. Simply place the assignment immediately above the While clause.
___________________________
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
int main()
{
int i;
int count = 0;
int singleVowel = 0;
/*************************************...
/* 50 is space enough for text and terminating character. */
char buffer[50];
printf("Enter a line of text: ");
fgets(buffer, sizeof(buffer), stdin);
/* Copy input into a character pointer for further processing. */
/* First, allocate memory; and, then do the copying. */
char * copy_str = malloc( strlen(buffer) + 1);
strcpy(copy_str, buffer);
/*************************************...
/* Now, lets iterate through each character in the string. */
while (*copy_str++ != '\0')
{
switch(*copy_str)
{
/* Check for a vowel. */
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
/* We have found a vowel; */
/* so, check to see if the preceding character was a vowel */
if (singleVowel = =1)
/* Increase the count of consecutive vowels */
count++;
else
/* Here, the preceding character was not a vowel */
/* If the next character is a vowel, */
/* then it will counts as being a consecutive vowel. */
singleVowel = 1;
default:
/* This particular character is not a vowel. */
/* So, any next vowel will not be a consecutive one */
singleVowel = 0;
}
}
printf("In text, we have %d consecutive vowels.\n", count);
return 0;
}
________________________
survey research
C programming?
pointers,functions,characters
C programming?
Yes!
Reply:http://www.physics.drexel.edu/courses/Co...
More advanced
http://www.augustcouncil.com/~tgibson/tu...
Remember, variables contained as pointers don't contain data, just reference the memory of another variable
so if
int a = 3;
int *b = %26amp;a
*b = 7
then a =7
Reply:What is the question?!?
I am a C++ programmer and know some things about C. But you do not have a question!
Reply:Ok, I'll play.
pointer = variable designed to hold an address where the data "lives" in memory = be careful to initialize or go directly into la-la-RAM
functions = statements grouped together to be reused or 'called' many times = more efficient coding
char = character = smallest allocated storage unit
C programming?
Yes!
Reply:http://www.physics.drexel.edu/courses/Co...
More advanced
http://www.augustcouncil.com/~tgibson/tu...
Remember, variables contained as pointers don't contain data, just reference the memory of another variable
so if
int a = 3;
int *b = %26amp;a
*b = 7
then a =7
Reply:What is the question?!?
I am a C++ programmer and know some things about C. But you do not have a question!
Reply:Ok, I'll play.
pointer = variable designed to hold an address where the data "lives" in memory = be careful to initialize or go directly into la-la-RAM
functions = statements grouped together to be reused or 'called' many times = more efficient coding
char = character = smallest allocated storage unit
C programming!!!help!!!?
i cant understand clearly the uses of pointers arrays...what are macros??the preprocessor statements??
please briefly explain these to me...or give me some very USEFUL links....
thank you very much!!
C programming!!!help!!!?
Hint: google.com is very useful.
Macros: http://gcc.gnu.org/onlinedocs/cpp/Macros... %26gt;%26gt; found with "C Macros"
Preprocessor: http://gcc.gnu.org/onlinedocs/cpp/ %26gt;%26gt; found with "C Preprocessor"
Pointers and Arrays: http://c-faq.com/ %26gt;%26gt; I know this one but Google will get it for you as it is ridiculously popular and well known
Reply:pointer-it is a variable which stores the address of the that variable to which it points.
for eg-int*j
j=%26amp;a;
now when you print j it wiil show you the address of a
and when you print *j it will show you the value of a.
arrays -the are used to store various values of same data type under common variable name.
macro-you can type a name in a program and define it above void main.during compilation where ever the name ccurs the definition is placed tis is macro.
what i would suggest you isif u live in india then you buy yashavant kanetkar(let us c) if you are a bigenner.
if you want to form strong basis in pointers you should go for-
pointers in c(yashavant kanetkar).it is a thin book.
the books r written in easy language.
90% computer studying college students(Indian) recommend this book for beginners.
please briefly explain these to me...or give me some very USEFUL links....
thank you very much!!
C programming!!!help!!!?
Hint: google.com is very useful.
Macros: http://gcc.gnu.org/onlinedocs/cpp/Macros... %26gt;%26gt; found with "C Macros"
Preprocessor: http://gcc.gnu.org/onlinedocs/cpp/ %26gt;%26gt; found with "C Preprocessor"
Pointers and Arrays: http://c-faq.com/ %26gt;%26gt; I know this one but Google will get it for you as it is ridiculously popular and well known
Reply:pointer-it is a variable which stores the address of the that variable to which it points.
for eg-int*j
j=%26amp;a;
now when you print j it wiil show you the address of a
and when you print *j it will show you the value of a.
arrays -the are used to store various values of same data type under common variable name.
macro-you can type a name in a program and define it above void main.during compilation where ever the name ccurs the definition is placed tis is macro.
what i would suggest you isif u live in india then you buy yashavant kanetkar(let us c) if you are a bigenner.
if you want to form strong basis in pointers you should go for-
pointers in c(yashavant kanetkar).it is a thin book.
the books r written in easy language.
90% computer studying college students(Indian) recommend this book for beginners.
Subscribe to:
Posts (Atom)