GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Apr-2008, 03:09
Ali.M.Habib Ali.M.Habib is offline
New Member
 
Join Date: Apr 2008
Posts: 3
Ali.M.Habib is on a distinguished road
Question

How can I solve this error


I writed down this program

[c]

#include<conio.h>
#include<stdio.h>
main()
{
clrscr();
struct data
{
char name[3][10];
char mail[3][40];
char no[3][10];
}a1,a2;


printf("\nEntr the name:");
goto end;
//intring the data of the name
for(int c=0;c<=2;c++)
scanf("%s",a1.name[c]);


printf("\nEntr the mails:");
//intring the data of the name
for( c=0;c<=2;c++)
scanf("%s",a1.mail[c]);

printf("\nEntr the Numbers:");
//intring the data of the name
for( c=0;c<=2;c++)
scanf("%s",a1.no
CPP / C++ / C Code:
);

end:

getch();
}         

the first goto in my code (goto end) give compilation error :

goto hypasses intialization of local variable.

How can I solve that, because it appeared to me again in a nother code
  #2  
Old 28-Apr-2008, 04:00
mamntc02 mamntc02 is offline
Junior Member
 
Join Date: Mar 2008
Location: Barcelona - Catalonia
Posts: 53
mamntc02 has a spectacular aura about

Re: How can I solve this error


Hi,

There's no error on goto, besides use a goto. You should never use goto if is possible to avoid, and always is possible, at least that's my opinion. Goto makes very difficult to find errors in code related with it.

However, there's other errors:
  • main always return int, so a C skeleton code:
    CPP / C++ / C Code:
    int main(){
       ...
       return 0;
    }
  • c variable is not declared in for statements. If you declare
    CPP / C++ / C Code:
    for(int c = 0; c < XXX; c++)
    c is local in for statement and it's destroyed when exits the 'for loop'. So, when you use again in next 'for loop' you must declare again, because it doesn't exists. Of course, you can also declare local in whole main function.
Regards
__________________
Please, correct me if I'm wrong, and sorry for my english ;)
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.