•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 425,778 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,340 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 272 | Replies: 6
![]() |
So basically i got to make program where you can add rows, inside those rows numbers and count in each row and all rows pair number sum.
This far im done and everything is working. Now part which don't want work. I need make option to make rows longer or shorter. For example:
row1 contains 1,4,5,2,4
row2 contains 1,2,5
i want make row1 longer and add 6. row1 now will contain 1,4,5,2,6
so here is code i made so far:
any sugestions?!
This far im done and everything is working. Now part which don't want work. I need make option to make rows longer or shorter. For example:
row1 contains 1,4,5,2,4
row2 contains 1,2,5
i want make row1 longer and add 6. row1 now will contain 1,4,5,2,6
so here is code i made so far:
case '3':{
clrscr();
row=0;
printf("\n Which row length you want change?");
flushall();
scanf("%hd",&row);
g=row-1; //this is for going to row[0] element
elemcount=lengthie[g]; //this count how much elements i got it my row currently
printf("\n%hd.row length now is %hd\n",g+1,lengthie[g]);
printf("For how much you want change row length??");
scanf("%hd",&change);
if (change=0){printf("Row length not changed");}
if (change<0){ newlenght=vecaisskaits-change;lengthie[g] = (short int) realloc(newlenght, sizeof(short int));}
if (change>0){ newlenght=elemcount+change;
lengthie[g] = (short int) realloc(newlenght, sizeof(short int));
for(q=elemcount;q=lengthie[g];q++){
printf("\n Insert %hd. row %d. element",g+1,q);
flushall();
scanf("%hd",&elements[g][q]);
}
} */
getch();
break;}•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,779
Reputation:
Rep Power: 11
Solved Threads: 185
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,779
Reputation:
Rep Power: 11
Solved Threads: 185
No, those are pointers.
Vectors are a kind of array that can grow and shrink very easy. An example:
Vectors are a kind of array that can grow and shrink very easy. An example:
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <vector> int main () { std::vector<int> my_buffer; my_buffer.push_back(2); my_buffer.push_back(5); std::cout << "My_buffer has " << my_buffer.size() << " ints in it"; std::cout << "The first number is " << my_buffer[0]; std::cin.get(); return 0; }
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,779
Reputation:
Rep Power: 11
Solved Threads: 185
In that case, you have some serious problems 
As my signature says '= != =='. You have = and == mixed up:
here:
and here:
flushall(),clrscr(),and getch()
won't work on standard compilers only on your Turbo thing, so get rid of 'em. Use getchar() to pause the program.
And I haven't looked at your logic yet.
Since this is more a C then a C++ question, I'll ask a mod to move your thread.

As my signature says '= != =='. You have = and == mixed up:
here:
for(q=elemcount;q=lengthie[g];q++)
and here:
if (change=0)
flushall(),clrscr(),and getch()
won't work on standard compilers only on your Turbo thing, so get rid of 'em. Use getchar() to pause the program.
And I haven't looked at your logic yet.
Since this is more a C then a C++ question, I'll ask a mod to move your thread.
Last edited by niek_e : May 16th, 2008 at 4:39 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
Your top array (the one containing arrays) should be defined something like (assuming you are storing ints):
Now you must decide how to know how long each array is. You could store its length as the first integer in the array. For example:
Hope this helps.
int[] lists[ 10 ]; // Ten arrays of variable length.Now you must decide how to know how long each array is. You could store its length as the first integer in the array. For example:
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> int main() { int[] lists[ 10 ]; int i, j; int *make_int_subarray( int length ); // Initialize for (i = 0; i < 10; i++) lists[i] = NULL; // Fill some of the sub-arrays for (i = 0; i < 6; i++) lists[i] = make_int_subarray( (i+1) * 2 ); // Print the arrays puts( "The arrays are:" ); for (i = 0; i < 10; i++) { for (j = 1; j < lists[i][0]; j++) printf( "%i ", &lists[i][j] ); printf( "\n" ); } // Free all memory for (i = 0; i < 10; i++) if (lists[i] != NULL) { free( lists[i] ); lists[i] = NULL; } return 0; } int *make_int_subarray( int length ) { int i; // Allocate storage for the array int *result = (int *)malloc( (length+1) * sizeof(int) ); // Store its length result[0] = length; // Fill it with numbers: 1, 2, 3, ... for (i = 1; i <= length; i++) result[i] = i; return result; }
Hope this helps.
Last edited by Duoas : May 16th, 2008 at 9:27 pm. Reason: Made it compilable.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Search 2Dim array (Java)
- How can i make perticular row or perticular cell of a JTable as Editable dynamically (Java)
- select row in datagrid....need help (VB.NET)
- how to set up my for loop to print my array in reverse (Java)
- Algorithm Problems (Java)
Other Threads in the C Forum
- Previous Thread: Pls Help.. A simple used car market
- Next Thread: IPC repeated attachment of shared memory segment at a fixed address.



Linear Mode