I want to write a program that will take an input,determine it whether it is integer array or string. and then we will be abble to insert an elwment giving two parameters. 1. element, 2. position. I have done, given bellow but can't finish it. Is there anyone for me to help?
// insertion.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdlib.h>
int get_arr(char arr[])
{
int i=0,isInt=0,j=0,IntArr[50];
while(arr[i-1]!='\n')
{
scanf("%c",&arr[i]);
i++;
}
if(arr[0]<58)
continue;
else
{
i=0;
while(arr[i]!='\0')
{
if(arr[i]!=' ')
{
arr[i]=arr[i];
i++;
}
}
return isInt;
}
i=0;
while(arr[i]!='\0')
{
while(arr[i]!=' ')
{
IntArr[j]=arr[i];
i++;
}
arr[j]=atoi(IntArr);
j++;
}
isInt=1;
return isInt;
}
int arr_len(char arr[])
{
int i=0;
while(arr[i]!='\0')
i++;
return i;
}
int main()
{
char arr[100],input[5];
int i,len,pos=0,isInt=0;
for(i=0; i<100;i++)
{
arr[i]=input[i]='\0';
}
printf("Input an array : ");
isInt=get_arr(arr);
len=arr_len(arr);
printf("Taken array : ");
for(i=0;i<len;i++)
printf("%c",arr[i]);
printf("Enter input element and position:\n");
scanf("%s %d",&input,&pos);
input=atoi(input);
for(i=len;i>=pos-1;i--)
arr[i]=arr[i-1];
arr[pos-1]=input;
printf("After insertion : ");
for(i=0;i<len;i++)
printf("%c",arr[i]);
printf("\n");
return 0;
}