Computing.Net > Forums > Programming > C++ pointer

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ pointer

Reply to Message Icon

Name: mahd
Date: November 12, 2004 at 15:30:23 Pacific
OS: XP
CPU/Ram: 933/256
Comment:

hello there..i have a major problem with my C++ course..and i wish that someone can help me with it..
the question says:

Write a function named ShiftToRight that takes as parameters a pointer to an array of integers, the array size, and a position in the array pos. The function should shift the elemnt to the array one step to the right starting from pos.
The prototype of the function is:
void ShiftToRight(int *array, int *sizeptr, int pos);

thanx in advance



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: November 12, 2004 at 15:39:01 Pacific
Reply:

It appears that you are not asking for help, but asking for someone to do your homework. We don't do homework here (click here).

You're best bet for help would be to try to code this and then ask questions about problems, or to ask a specific question.

To be technical about it, you haven't even asked a question, but just told us that you have a problem.


0

Response Number 2
Name: mahd
Date: November 12, 2004 at 15:55:42 Pacific
Reply:

hello there..

i've worked out with the question and i managed to solve it.. and here is my code..

#include<stdio.h>
void ShiftToRight(int *array,int *size,int pos )
{
int i;

for (i=(*size);i>pos;i--)
*(array+i)=*(array+i-1);
*(array+pos)=*(array+pos);
*size++;

}

void main()
{
int arr[7],s=7,pos,i;

printf("enter the element of the array:\n");

for(i=0; i<7;i++)
scanf("%d",&arr[i]);
printf("enter the postion \n");
scanf("%d",&pos);

ShiftToRight(arr,&s,pos );

printf("\n\nThe array after shifting:\n");
for( i=0;i<7;i++)
printf("%d ",arr[i]);

}


-----------
the second part of the question says:
Write a function InsertOne that takes as parameters: a pointer to an array of integers number of elements in the array, and a constant array size. The function should insert '1' after akk iccurrences of the sequence '100' in the array. Use the above function ShiftToRight to shift the elements before inserion.
The function prototype is
void InsertOne (int *arr, int *sizeptr, const int SIZE);
Note: use pointer operations only.
Example:
if the original array is:
1 1 0 0 0 1 0 0
Then after calling the function the array would be like the following:
1 1 0 0 1 0 1 0 0 1

------------------
thats my code..but i do have some errors..any help plz

#include<stdio.h>

void shiftToRight(int *array, int *sizeptr, int pos)
{
int i;
for (i=(*sizeptr);i>pos;i--)
*(array+i)=*(array+i-1);
*(array+pos)=1;
*sizeptr++;
}
void insertOne ( int *arr ,int*sizes )
{
int i ,size;
for (i=0 ;i<*sizes;i++)
if (*(arr+i)==1 && *(arr+i+1)==0 && *(arr+i+2)==0)
{
i=i+3;
ShiftToRight(arr,&size,i);
}
}

int main()
{
int a[9]={1,1,0,0,0,1,0,0},size=9;
int *aptr=a;
int *sizeptr;
sizeptr=&size;

insertOne(aptr,sizeptr);
printf("\n\nThe array after shifting:\n");
for(int i=0;i<9;i++)
printf("%d ",a[i]);
return 0;
}


0

Response Number 3
Name: BlueRaja
Date: November 13, 2004 at 22:40:43 Pacific
Reply:

Damn it mahd, don't encourage them!!!

You may think you're helping them, but in the long run, you're really not.

AKhalifman@hotmail.com


0

Response Number 4
Name: mahd
Date: November 13, 2004 at 22:46:44 Pacific
Reply:

helping them!!

its my problem and i'm asking for help

i copied the code and i'm asking for help to fix the error :)

any help?


0

Response Number 5
Name: BlueRaja
Date: November 13, 2004 at 23:00:23 Pacific
Reply:

...Raja's an idiot, my apologies.
It really is late :S :(

AKhalifman@hotmail.com


0

Related Posts

See More



Response Number 6
Name: mahd
Date: November 14, 2004 at 17:47:44 Pacific
Reply:

so..any help with my error?


0

Response Number 7
Name: Don Arnett
Date: November 14, 2004 at 20:47:19 Pacific
Reply:

I realize that you are getting a lot of hassles and not much help so far, but it's my bedtime and I don't feel like fine toothing your code when I don't know what I'm looking for.

What type of errors are you getting?

The program doesn't compile? If not, what error message(s) are you getting?

It runs but fails. How does it fail? It just quits? I causes you monitor to explode?

It runs but gives wrong answers.

Details besides "I get errors" will be helpful to a more timely answer.


0

Response Number 8
Name: mahd
Date: November 15, 2004 at 12:26:44 Pacific
Reply:

the error says : Call to undefined function 'ShiftToRight' in the function insertOne (int *,int *)


0

Response Number 9
Name: Jim Langston
Date: November 15, 2004 at 15:37:18 Pacific
Reply:

Your function is declared as shiftToRight, but you are calling ShiftToRight.

Notice the small and capital 'S'.

C and C++ are case SenSiTivE


0

Response Number 10
Name: mahd
Date: November 15, 2004 at 17:52:20 Pacific
Reply:

i changed it and i got another error..

Linker Warning: No module definition file specified: using defaults


0

Response Number 11
Name: BlueRaja
Date: November 15, 2004 at 19:47:18 Pacific
Reply:

Honestly, that first error shows us that you're not even TRYING to fix it yourself...

AKhalifman@hotmail.com


0

Sponsored Link
Ads by Google
Reply to Message Icon

C++ major probs Perl - how to print to fi...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ pointer

C++ Pointer problem www.computing.net/answers/programming/c-pointer-problem/11700.html

c++ pointers with arrays www.computing.net/answers/programming/c-pointers-with-arrays/14851.html

pointer www.computing.net/answers/programming/pointer/1548.html