Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- typedef struct node_ {
- char* val;
- struct node_ * next;
- } node;
- node *head = 0;
- node *curr = 0;
- node *nodeWithString(char *string) {
- node * out = malloc(sizeof(node));
- out->val = string;
- out->next = 0;
- return out;
- }
- void printList() {
- curr = head;
- while (curr != 0) {
- if (curr->next == 0) {
- printf("%s\n", curr->val);
- } else {
- printf("%s -> ", curr->val);
- }
- curr = curr->next;
- }
- }
- void insertNode(char *string) {
- node *new = nodeWithString(strdup(string));
- if (head == 0) {
- head = new;
- } else {
- curr = head;
- while (curr->next != 0) {
- curr = curr->next;
- }
- curr->next = new;
- }
- }
- int max(int one, int two) {
- int out = one;
- if (two > one) {
- out = two;
- }
- return out;
- }
- int main(int argc, char** argv) {
- if (argc != 2) {
- printf("ERROR: This program takes exactly one argument.\n");
- return 1;
- }
- int inputLength = strlen(argv[1]);
- char buffer[inputLength];
- memset(buffer,0,inputLength); // Clear buffer
- int i;
- for (i = 0; i < strlen(argv[1]); i++) {
- char c = argv[1][i];
- if (isalpha(c)) {
- buffer[strlen(buffer)] = c; // Add character to buffer
- } else {
- insertNode(buffer);
- memset(buffer,0,inputLength); // Clear buffer
- }
- }
- insertNode(buffer);
- printList();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement