473,511 Members | 15,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop forever

10 New Member
I am trying to make this function keep going on until I call an interrupt or, delete function in my GCC. HEre is what I have. I tried putting a while(1) loop in my driver.c but it does not stop.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int sreplace(char newc, char oldc, char *s)
  4. {
  5.  
  6.         int cnt;
  7.         cnt = 0;
  8.  
  9.         while(*s !='\0') //loop to run till the end of the string
  10.         {
  11.                 if(*s == oldc) //if the char found which to be replaced
  12.                 {
  13.                         *s = newc; //replace
  14.  
  15.                         cnt++;
  16.                 }
  17.                 s++;
  18.  
  19.         }
  20.         return cnt;
  21. }
  22.  
  23.  
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. char *strmatch(char *str, char *s)
  4. {
  5.  
  6.  
  7.         char *tmp;
  8.  
  9.         while(*str!='\0'){
  10.                 tmp = s;
  11.                 while(*tmp !='\0' && *str == *tmp)
  12.                 {
  13.                         str++;
  14.                         tmp++;
  15.                 }
  16.                  if(*tmp =='\0')
  17.                  {
  18.                         return str;
  19.                  }
  20.  
  21.         str++;
  22.         }
  23.         return(NULL);
  24. }
  25.  
  26.  
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int sreplace(char newc, char oldc, char *s);
  3. char *strmatch(char *str, char *s);
  4.  
  5. int main()
  6. {
  7.         char line1[1024];
  8.         char line2[1024];
  9.         char *ptr;
  10.         char *s1, *s2;
  11.  
  12.  
  13.         fgets((s1=line1),1024,stdin);
  14.         fgets((s2=line2),1024,stdin);
  15.  
  16.          sreplace('\0','\n', line1);
  17.          sreplace('\0','\n', line2);
  18.  
  19.         ptr = strmatch(s1,s2);
  20.  
  21.         printf("%s\n",ptr);
  22.  
  23.  
  24.         return 0;
  25.  
  26. }
  27.  
  28.  
Sep 20 '07 #1
2 4155
mattmao
121 New Member
Hi.

If you want to have a forever loop, try this:

while(1)
{

code block;

//loop control goes here:
if(test method)
break;
}

This break; statement would let you terminate the while loop.
Sep 21 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
Hi.

If you want to have a forever loop, try this:

while(1)
{

code block;

//loop control goes here:
if(test method)
break;
}

This break; statement would let you terminate the while loop.
or you could put the test method in the while condition...
Sep 21 '07 #3

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

Similar topics

0
6546
by: Brent Wege | last post by:
Hey guys, kinda scratching my head on this one. Each of these insert queries takes about 1 second in QA, but when I decide to loop it 100 times instead of manually inserting it 100 times, it will...
43
5528
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
1
1382
by: Sokar | last post by:
Hello, I was wondering if anyone could help me out. I have devised a wee menu system with 5 options. the way to select an option is to select a number 1 - 5 and then there is a switch block to...
3
15944
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
32
4595
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
5
2772
by: Mike D | last post by:
Attached is my code. Which I know there is a better way of writing however this is what I came up with and it works until the value is null or not = to the <> value. 'Do While rdrSQL.Read() ...
14
5875
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
29
5055
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
5
870
by: Vasileios Zografos | last post by:
Hi everyone, can somebody please what is this in a heading of a for loop? I have never seen this before: for(;;) { ..... }
70
3452
by: hstagni | last post by:
When i read a key using getchar() inside a loop, the program stops and wait for a key to be pressed. I actually want the program to continue its execution until a key is pressed. Look at this...
0
7237
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
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
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
5659
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,...
0
3219
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...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.