FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

euroeng.c [Pt. 1]




//euroeng.c converts English text to Euro-English.
//usage: ./euroeng <filename>


#include <stdio.h>
#include <ctype.h>
#include <string.h>

typedef struct entryNode {
char ch;
struct entryNode *next;
} entry;

void deleteNode(entry *node) {
node->ch = node->next->ch;
entry* pTemp = node->next->next;
free(node->next);
node->next = pTemp;
}

int main(int argc, char *argv[]) {
//Initialize variables
FILE *stream;
char c;

//Open file stream
stream = fopen(argv[1], "r");

//Initialize pointers for entry linked list
entry *head = NULL, *hover = NULL;

if(stream == NULL) {
perror("Error opening the file");
return 0;
}
else {
printf("Your file contains:\n\n");
do {
//Create new node
entry *node = (entry *) malloc(sizeof(entry));

//Get character from stream and save to node
c = fgetc(stream);
node->ch = c;

//Set next to NULL
node->next = NULL;

//Set pointers
if(head == NULL) {
head = node;
hover = node;
}
else {
hover->next = node;
hover = node;
}

//Print letter
printf("%c", hover->ch);

} while(c != EOF);
fclose(stream);
}

printf("\n\nConverted text in Euro-English:\n\n");



1 blog comments below

Euro-English?
Hello_World on Tue Mar 20, 2012 10:36 am



FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.