Amazon Interview Report
- 0of 0 votes
Answerstime consuming of removing space from a string.
- jdicky May 03, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersremove spaces when they occur more than one time consecutively in string.
- jdicky May 03, 2012 in United States#include<stdio.h> #include<string.h> #include<stdlib.h> #define SPACE ' ' main() { char string[100], *blank, *start; int length, c = 0, d = 0; printf("Enter a string\n"); gets(string); length = strlen(string); blank = string; start = (char*)malloc(length+1); if ( start == NULL ) exit(EXIT_FAILURE); while(*(blank+c)) { if ( *(blank+c) == SPACE && *(blank+c+1) == SPACE ) {} else { *(start+d) = *(blank+c); d++; } c++; } *(start+d)='\0'; printf("%s\n", start); free(start); return 0;
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C