Apr 28, 2011 at 11:53am UTC
I'm trying many times , many ways , but it's difficult !!!
What is the problem ?
Anyone help me !!! Please ....I'm crazy .... Rsssssss
#include<iostream>
#include<string.h>
#include<conio.h>
#include<windows.h>
//variaveis globais
int vf=0; //variavel de controle
int const linha=2;
int const coluna=40;
bool sim;
using namespace std;
//funçoes
void insere(char [][coluna],int); //o int depois da virgula vai para linha
void escreve(char [][coluna],int);
void falha();
int main()
{
char arrai[linha][coluna];
int menu;
cout<<"§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§";
cout<<endl<<"ESCOLHA UMA OP\x80\xb6O"<<endl<<endl;
cout<<"1 - inserir nome\n";
cout<<"2 - Exibir nome\n";
cout<<"3 - Sair\n";
cout<<"§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§\n\n\n";
cout<<"DIGITE UMA ALTERNATIVA --> ";
cin>>menu;
while(1){
switch(menu){
case 1:
insere(arrai[][coluna],linha);
break;
case 2:
escreve(arrai,linha);
break;
case 3:
falha();
break;
Default:
cout<<"ERRO CRITICO FAÇA UMA FACULDADE PARA APRENDER A \n PROGRAMAR !\n\n";
}
}
getch();
return 0;
}
//funçao para inserir nome no array
void insere(char array[][coluna],int line)
{
char peganome[coluna];
char pergunta;
while(sim){
cin.ignore();
cout<<"Digite um nome --> ";
cin.getline(peganome,coluna);
if(cin.bad()){cout<<"Erro na leitura";}
if(strlen(peganome) > coluna){cout<<"O nome ultrapassa o tamanho permitido !!!";falha();}
for(int y=0; y < strlen(peganome);y++)
{
array[vf][y]=peganome[y];
}
cout<<endl<<endl;
cout<<"Deseja continuar ? ";
cin>> pergunta;
if(pergunta == 'n' || pergunta == 'N'){sim=false;}
vf+=1;
if(vf == 2){cout<<"Tabela cheia !!!\n\n";sim=false;}
}
}
//mostrar conteudo do array
void escreve(char arrais[][coluna],int lin)
{
char peganome[coluna];
for(int n=0; n < vf; n++)
{
for(int m=0; m < strlen(peganome); m++)
if(arrais[n][m] != '\0')
{
cout<<arrais[n][m];
}
cout<<endl;
}
}
//para sair do programa
void falha()
{
cout<<"Saindo do programa ...";
Sleep(1000);
exit(1);
}
I'm compiling with Dev C++ and the error is :
expected primary-expression before ' ] ' token
Apr 28, 2011 at 12:10pm UTC
I try , compile but I don't get the effect wait !!!
Apr 28, 2011 at 1:17pm UTC
1 2 3 4 5 6 7 8
switch (menu)
{
case 1:
insere(arrai[][coluna],linha); // should be: insere(arrai,linha);
break ;
case 2:
escreve(arrai,linha);
break ;
You've got it correct for case 2, you need to fix case 1.
Last edited on Apr 28, 2011 at 1:20pm UTC
Apr 28, 2011 at 4:59pm UTC
No if array is empty , I can't choice 2.
Compile yes compile but have logic error !!!
Ow friend thank for you help me ...
Continue please ... I wait your answer ..