Hi,
Again a question from Koffman's book;
Question inputs a string and separate it into components.
For example;
Input :
ALT1203S14
Output:
Warehouse: ALT
Product: 1203
Qualifiers: S14
My broken code:
Code:#include <stdio.h>
#include <string.h>
int main(void)
{
int first, next,n;
char code[40], warehouse[20], qualifiers[20], product[20];
printf("Enter product code> ");
scanf("%s", code);
first = 0;
next = 1;
n = 0;
while(next<strlen(code)){
next++;
//n++;
if(code[next] >= 'A' && code[next] <= 'Z'){
n = n + 2;
strncpy(warehouse, code, next - n);
warehouse[next - n] = '\0';
first = next - n;
//next = next - n;
}
if(code[next] >='1' && code[next] <= '9'){
strncpy(product, &code[first], next - first );
product[next] = '\0';
first = next-n;
}
if(code[next] >= 'A' && code[next] <= 'Z'){
strncpy(qualifiers, &code[first], next - first);
qualifiers[next-n] = '\0';
first = next;
}
}
printf("Warehouse: %s\nProduct: %s\nQualifiers: %s",warehouse,\
product, qualifiers);
printf("\n%d\n%d", n,next);
return(0);
}