玛丽安,
请通过以下实现目的。它应该合理地工作。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
const char *src_strings[]={"WADMIN", "WADMIN", "WADMIN", "WADMIN", "PALA", "PALA", "PALA", "PALA"}; //source array of char pointers
char *dest_strings[8]; //Destination array of character pointers
int string_count,length,cindex;
printf("Modified Strings\n");
printf("================\n");
//Traverse through the strings in the source array
for(string_count=0;string_count<8; string_count++)
{
//Compute the lenght and dynamically allocate the
//required bytes for the destination array
length=strlen(src_strings[string_count]);
dest_strings[string_count]= (char*)malloc(sizeof(length-1));
//Copy characters to destination array except first and last
for(cindex=1; cindex<length-1; cindex++)
{
*(dest_strings[string_count]+cindex-1)=*(src_strings[string_count]+cindex);
}
//Append null character
*(dest_strings[string_count]+cindex)='\0';
printf("%s\n",dest_strings[string_count]);
//Free memory as it is not needed
free(dest_strings[string_count]);
}
return 0;
}
样本输出
Modified Strings
================
ADMI
ADMI
ADMI
ADMI
AL
AL
AL
AL