creating an array of pointers to a struct in C?
115383
Another "answerer" correctly explained that you\ncould declare an array of pointers to a struct as:\n\n    struct foo *p[100];\n\nbut it might be useful for you to know about a\nutility that has been floating around the internet\nfor at least a couple of decades which tries to\n"translate" between a human readable syntax and\nC/C++ syntax for data declarations and casts.\nThe utility is "cdecl", and can easily be found\nwith google.\n\nAs an example, on this problem:\n\n$ cdecl\ncdecl> declare p as array 100 of pointer to struct foo\nstruct foo *p[100]\n\nWhat's interesting is that it can reverse the translation:\ncdecl\ncdecl> explain struct foo *p[100]\ndeclare p as array 100 of pointer to struct foo\n\nIt's not so exciting for something simple like this example,\nbut if you run across a declaration like:\n\nint *const*(**f)(int*,int*);\n\nyou can feed it to cdecl to get at least *some* idea of\nwhat it means:\n\ncdecl> explain int *const*(**f)(int*)\ndeclare f as pointer to pointer to function (pointer to int) returning pointer to const pointer to int\n\nSimilarly, it will generate "cast" syntax, ie:\n\ncdecl> cast p into pointer to pointer to function returning pointer to int\n(int *(**)())p
686663
The asterix indicate which dimension of the array should be output.\n\nprintf allows you to format the output string. Your printf string basically says, "Print four decimal columns. First column, give me the first dimension of the array; second, give me the second dimension; etc."\n\nThe asterixes are pointers. Each asterix indicates which position of the array the statement should output.
295277
#include <iostream.h>\n#include <string.h>\n\nstruct String\n{\npublic:\nchar * Data;\nint Length;\n};\nString operator+(const String & s1,const String & s2)\n{\nchar * s3=new char [s1.Length+s2.Length];\nstrcpy(s3,s1.Data);\nstrcat(s3,s2.Data);\n\nString Out;\nOut.Data=s3;\nOut.Length=s1.Length+s2.Length;\nreturn Out;\n}\n\n//you can't directly overload char * because at least one operand of any overloaded operator must be of some user-defined type.\n\n//u can use strcat
98474
you can use c compiler (cc)\ncc srcfile.c -o destfile
52447
pointer is a variable that holds another variables memory adress. an it can be use like variable.
838865
What language is this?  It looks like the result of a night of unbridled passion between C, C++, and Java!\n\nSo, you know that "x->y" is equivalent to "(*x).y", right? So, even though you never used . directly, it's apparently what the compiler is seeing. Of course, . can only be used with a struct, and it is complaining that you are using it with something that is not a struct. However, the error is confusing, since the problem is really caused by a problem with pointers.\n\n Consider b[10]  (and b[9]).  b is a pointer to blocks. The [ ] operator dereferences this pointer, so that b[10] has type block, not block *.  Since -> can only be used with pointers (block *), the compiler generates an error. \n\nThink carefully about what you want to do, draw a picture on paper, and make sure your types all make sense.  Good luck.
551498
I'm no "C" expert, but in Delphi this is a Windows system call, and I'm sure it will be a similar implementation in C; just alter the syntax as necessary...
61693
Assuming C++, the address in memory of p... More specifically, the starting of the character array...
314740
There are a few ways to do this, depending on the behavior you want. You can make a class that contains the array (constructor will take the size of the array). Then you implement/overload all the operators you are interested in. In these operators, you can overload [] to cause the index to wrap (if the size of the array was 10 and you did [10] you would get the 0'th element. Or you could have [10] return [9] element all the time. With templates:\n\ntemplate<class T, int n> class Array{\n\npublic:\nT& operator[](int i) {\nint j = i;\nif(i < 0){\n   j = 0;\n}\nif(i > n - 1){\n   j = n - 1;\n}\n\nreturn data[j];}\n\nprivate:\nT data[n];\n};\n\nor something like that.
705410
Array is the perfect answer to a problem of declaring too much variables. How so? It's simply because an array represents a set of elements of same data type. Instead of declaring 50 variables using 50 different names, you could just use one name and just add index to it. Take for example a program with 20 variables, i could declare an array consisting of 20 elements and name that array discover. to access the first element of discover i'll just access discover[0] (because the index starts always zero and not 1) and to access the second element, i'll put discover[1], and so on until discover[19]. you could loop this by declaring another variable for the index. say, discover[num], in which num is a variable for the index. you could make this to input the variable :\n for (num=0; num<20; num++)\n{cin>>discover[num]; }\nit is quite simple... all you need is practice...
363476
There's not enough information, what type of list, I don't think you mean an Enumerated List, and into what type of split, are you talking about linked lists, or something like indexing using trees to navigate or manage keys?
751489
I don't see how you could access elements in an array past MAXINT. (Using array syntax.)\n\nSo the practical answer is MAXINT.
659498
because you are using a pointer to load the array. you are actually writing outside of the array, but it isnt causing any problems (yet) because a[] is the last variable you are using.\n\ntry this to see what I mean. declare another int after a[]\nint a[]={1,4,2,5,6,3,7,8);\nint b;\nmake b = 0;\nwriting to a[8] means you overwritting the NULL terminator, but try writing to a[9] (a[9] = 12;), print out b, and see what it is. you should see that it is now 12.
83035
#define __TEST__\n\n#include <stdio.h>\n\n#ifdef __TEST__\n#include <conio.h>\n#include <stdlib.h>\n#endif\n#define STACKSIZE 64\n\n\nint stack[STACKSIZE];\nstatic int stack_ptr=0;\n\nvoid overflow_test( int pos )\n{\nif( pos >= STACKSIZE )\n{\nputs( "Stack overflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid underflow_test( int pos )\n{\nif( pos < 0 )\n{\nputs( "Stack underflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid push( int value )\n{\noverflow_test( stack_ptr+1 );\nstack[stack_ptr++] = value;\n}\n\nint pop( void )\n{\nunderflow_test( --stack_ptr );\nreturn stack[stack_ptr];\n}\n\n#ifdef __TEST__\n\nvoid wait4keypress( void )\n{\nwhile( !kbhit())\n;\n}\n\nint main( void )\n{\natexit(wait4keypress); \npush(1);\npush(2);\npush(3);\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\n/* must cause stack underflow */\nprintf( "%d&#92;n", pop());\nreturn 0;\n}\n\n#endif  /* __TEST__ */
44673
Your program ran into code it couldn't execute or data it couldn't address.\n\nIf you wrote the code, look for things like uninitialized pointers, overwritten data structures, and anything else that could corrupt your code or data.
781094
Nobody is going to do your homework for you. \n\nIf you're supposed to write code examples that illustrate how two comparable programs might look, then do this. Write some simple programs in C, and then re-write the same program in C++ but put the functions your void main calls in a class and instantiate the class.
334651
If you use an array, then use the mod operator to choose the first element of the array to access the array once you have passed the last element of the array. \n\ni = 0; \nwhile (1)\n{\n   printf ("%d", a[i%n]); // 'n' is the size of the array\n   i++;\n}