| | |
problem in the pile
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
friends before any thing apologizes for English I am using translator because only of the brasil and I don't know how to write.
my problem is the following I have to create a program that reads a text and it prints the same text to the I thwart oh this that I did
my problem is the following I have to create a program that reads a text and it prints the same text to the I thwart oh this that I did
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <conio.h> #define max 10 typedef int TipoChave; typedef struct { char texto; } TipoItem; typedef struct Celula_str *Apontador; typedef struct Celula_str { TipoItem Item; Apontador Prox; } Celula; typedef struct { Apontador Fundo, Topo; int Tamanho; } TipoPilha; void FPVazia(TipoPilha *Pilha) { Pilha->Topo = (Apontador) malloc(sizeof(Celula)); Pilha->Fundo = Pilha->Topo; Pilha->Topo->Prox = NULL; Pilha->Tamanho = 0; } /* FPVazia */ int Vazia(TipoPilha Pilha) { return (Pilha.Topo == Pilha.Fundo); } /* Vazia */ void Empilha(TipoItem x, TipoPilha *Pilha) { Apontador Aux; Aux = (Apontador) malloc(sizeof(Celula)); Pilha->Topo->Item= x; Aux->Prox = Pilha->Topo; Pilha->Topo = Aux; Pilha->Tamanho++; } /* Empilha */ void Desempilha(TipoPilha *Pilha, TipoItem *Item) { Apontador q; if (Vazia(*Pilha)) { printf(" Erro lista vazia\n"); return; } q = Pilha->Topo; Pilha->Topo = q->Prox; *Item = q->Item; free(q); Pilha->Tamanho--; } /* Desempilha */ int Tamanho(TipoPilha Pilha) { return (Pilha.Tamanho); } /* Tamanho */ int main() { TipoPilha pilha; TipoItem item; Apontador p; FPVazia(&pilha); printf(" digite um texto"); int i=0; char palavra[30]; gets(palavra); while (palavra[i]!= '0'){for(i=0;palavra[i]!=(' 'and '0');i++){ item.texto=palavra[i]; Empilha(item, &pilha);}} while(!Vazia(pilha)){ printf(" %c \n", item.texto); Desempilha(&pilha,&item); if(palavra[i]!='0'){ i++;} } getch();}
Last edited by Narue; Nov 19th, 2008 at 9:41 am. Reason: added code tags
1) learn to properly format your code to make it easier to read and understand.
2) The for loop on line 80 is not formed correcly
2) The for loop on line 80 is not formed correcly
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <conio.h> #pragma warning(disable: 4996) #define max 10 typedef int TipoChave; typedef struct { char texto; } TipoItem; typedef struct Celula_str *Apontador; typedef struct Celula_str { TipoItem Item; Apontador Prox; } Celula; typedef struct { Apontador Fundo, Topo; int Tamanho; } TipoPilha; void FPVazia(TipoPilha *Pilha) { Pilha->Topo = (Apontador) malloc(sizeof(Celula)); Pilha->Fundo = Pilha->Topo; Pilha->Topo->Prox = NULL; Pilha->Tamanho = 0; } /* FPVazia */ int Vazia(TipoPilha Pilha) { return (Pilha.Topo == Pilha.Fundo); } /* Vazia */ void Empilha(TipoItem x, TipoPilha *Pilha) { Apontador Aux; Aux = (Apontador) malloc(sizeof(Celula)); Pilha->Topo->Item= x; Aux->Prox = Pilha->Topo; Pilha->Topo = Aux; Pilha->Tamanho++; } /* Empilha */ void Desempilha(TipoPilha *Pilha, TipoItem *Item) { Apontador q; if (Vazia(*Pilha)) { printf(" Erro lista vazia\n"); return; } q = Pilha->Topo; Pilha->Topo = q->Prox; *Item = q->Item; free(q); Pilha->Tamanho--; } /* Desempilha */ int Tamanho(TipoPilha Pilha) { return (Pilha.Tamanho); } /* Tamanho */ int main() { TipoPilha pilha; TipoItem item; // Apontador p; FPVazia(&pilha); printf(" digite um texto"); int i=0; char palavra[30]; fgets(palavra, sizeof(palavra), stdin); while (palavra[i]!= '0') { for(i=0; palavra[i]!=' ' && palavra[i]!='0';i++) { item.texto=palavra[i]; Empilha(item, &pilha);}} while(!Vazia(pilha)) { printf(" %c \n", item.texto); Desempilha(&pilha,&item); if(palavra[i]!='0') { i++; } } getch(); }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Vista Local Access Only Problem (Windows Vista and Windows 7)
- Server Not Found/Problem loading Page (Web Browsers)
- Suggests and solution to Histogram program problem please (C++)
- A simple problem (C)
- Front panel microphone jack problem (USB Devices and other Peripherals)
- Runtime error!! ACM problem (C++)
- Classes Problem (C++)
Other Threads in the C Forum
- Previous Thread: Creating a hash table in C
- Next Thread: Error when freeing some pointers !
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings structures suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






