Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

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;
}

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

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?

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.

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

Your function is declared as shiftToRight, but you are calling ShiftToRight.
Notice the small and capital 'S'.
C and C++ are case SenSiTivE

i changed it and i got another error..
Linker Warning: No module definition file specified: using defaults

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

![]() |
C++ major probs
|
Perl - how to print to fi...
|

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