/* * Example of using strncpy and strcpy functions * * Displays each elemental component, identified by an initial capital letter. */ #include #include #define NSIZE 30 int main() { char compound[NSIZE], elem[NSIZE]; int first, next; printf("Enter a compound, such as H2Co > "); gets(compound); // scanf("%s", compound); first = 0; for (next = 1; next < strlen(compound); ++next) if (compound[next] >= 'A' && compound[next] <= 'Z') { strncpy(elem, &compound[first], next - first); elem[next - first] = '\0'; printf("%s\n", elem); first = next; } printf("%s\n", strcpy(elem, &compound[first])); // last component return (0); }