473,468 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

goto problem

9 New Member
Here I have send my code .Actually I wanna delete this goto,because I heard goto is not good statement to use for experiance programmer.I wanna alternative for goto according to my code.It printf("test") is optional statement.I wanna after printf("i = %d, j-1 = %d\n", i, j - 1); goto the for loop in "i"
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, char *argv[])
  4. {
  5. int i;
  6. int j;
  7. int k;
  8. int ptr;
  9. int l;
  10. k=0;
  11.  
  12.    printf("0");
  13.    for (i = 2; i < argc; i++) {
  14.        for (j = 1; j < i; j++) {
  15.            ptr = strcmp(argv[j], argv[i]);
  16.            if (ptr == 0) {
  17. for (l=i;l<argc;l++){
  18.                argv[l] = argv[l + 1];
  19. }
  20.                i--;
  21.                printf("i = %d, j-1 = %d\n", i, j - 1);
  22.  
  23. goto loop;
  24.     }
  25. }
  26.            k++;
  27.            printf("k = %d\n", k);
  28.  
  29. loop:
  30. printf("test");
  31. }
  32. return 0;
  33. }
Jul 17 '07 #1
1 1567
JosAH
11,448 Recognized Expert MVP
Here I have send my code .Actually I wanna delete this goto,because I heard goto is not good statement to use for experiance programmer.I wanna alternative for goto according to my code.It printf("test") is optional statement.I wanna after printf("i = %d, j-1 = %d\n", i, j - 1); goto the for loop in "i"
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, char *argv[])
  4. {
  5. int i;
  6. int j;
  7. int k;
  8. int ptr;
  9. int l;
  10. k=0;
  11.  
  12.    printf("0");
  13.    for (i = 2; i < argc; i++) {
  14.        for (j = 1; j < i; j++) {
  15.            ptr = strcmp(argv[j], argv[i]);
  16.            if (ptr == 0) {
  17. for (l=i;l<argc;l++){
  18.                argv[l] = argv[l + 1];
  19. }
  20.                i--;
  21.                printf("i = %d, j-1 = %d\n", i, j - 1);
  22.  
  23. goto loop;
  24.     }
  25. }
  26.            k++;
  27.            printf("k = %d\n", k);
  28.  
  29. loop:
  30. printf("test");
  31. }
  32. return 0;
  33. }
You indentation is so horrible it makes me nauseous when I try to figure out what
is supposed to belong to what. Care to fix it?

kind regards,

Jos
Jul 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Michael | last post by:
Hi, I know I know its notoriously bad! I don't want to use it. I was wondering, does it still exist? If it does, I really don't understand how!? like what happens if you just goto halfway through...
52
by: Rick | last post by:
Hi, For portability, can an issue arise if we use while(1) for an infinite loop in C? If so, should we then use for(;;)? Thanks, Rick
28
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use...
17
by: SUMIT | last post by:
I wrote a program for removing comment from C source file for which i... 1.first constructed a DFA 2.used goto statement to write a program. now it was very easy to model DFA using goto & i...
19
by: Dave | last post by:
I'm building a research application that needs to be a super speed demon. I decided that one way to do this is to use goto loops instead of while() loops when I need them. that way, instead of...
77
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
67
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is...
17
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code...
59
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.