473,657 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need ASAP help with a function (program)!!!

64 New Member
I wrote this code, but I'm not able to test it because im getting 3 errors. So I'm not sure that this code will work properly or not!!!

the code in
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int rnd(char s1[],char s2[],char c[]);
  4. int GetSt(char s1[],char s2[],char c[]);
  5. void SearchAndPrint (char s1[], char s2[], char c[], int length);
  6.  
  7. int main ()
  8. {
  9.      char s1[41];
  10.      char s2[21];
  11.      char c[2];
  12.     int answer,m;
  13.     while(answer !='n')
  14.     {
  15.     m=rnd(s1,s2,c);
  16.     if (m==-1)
  17.     {
  18.         printf("ERROOORRR\n");
  19.         printf("wanna cont press enter or n to exit\n");
  20.           answer=getchar();
  21.          continue;
  22.     }
  23.     else
  24.     {
  25.          printf("wanna cont press enter or n to exit\n");
  26.           answer=getchar();
  27.     }
  28.     return 0;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35. int rnd(char s1[],char s2[],char c[])
  36. {
  37.     int i,n;
  38.      for(i=0;i<41;i++)
  39.          s1[i]=rand() %26 + 'A';
  40.          s1[i]='\0';
  41.  
  42.          n=GetSt(s1,s2,c);
  43.              if(n==-1)
  44.                  return -1;
  45.              else 
  46.                  return 1;
  47. }
  48.  
  49.  
  50. int GetSt(char s1[],char s2[],char c[])
  51. {
  52.     int n,i,length,m;
  53.      printf("enter a char\n");
  54.          c[0]=getchar();
  55.          if((n=getchar())!='\n')
  56.          {
  57.              printf("ERROOORRR\n");
  58.          while(n!='\n')
  59.          {
  60.              n=getchar();
  61.          }
  62.         return -1;
  63.          }
  64.          c[1]='\0';
  65.  
  66.          printf("enter char\n");
  67.          i=0;
  68.          while(i<21)
  69.          {
  70.              if( (m=getchar()) !='\n')
  71.              {
  72.                  if('A'<=m && m<='Z')
  73.                  {
  74.                  s2[i]=m;
  75.                  i++;
  76.                  }
  77.                  else if ('a'<=m && m<='z')
  78.                  {
  79.                      m=m-32;
  80.                      s2[i]=m;
  81.                      i++;
  82.                  }
  83.                  else
  84.                  {
  85.                      while(m!='\n')
  86.                  m=getchar();
  87.                          break;
  88.                  }
  89.  
  90.              }
  91.              else
  92.              {
  93.                  s2[i]='\0';
  94.                  break;
  95.              }
  96.          }
  97.          length=i;
  98.          if(i==21)
  99.          {
  100.              printf("error 2\n");
  101.              while(m!='\n')
  102.                  m=getchar();
  103.              return -1;
  104.          }
  105.          else if(i<2)
  106.          {
  107.              printf("error 3\n");
  108.              return -1;
  109.          }
  110.          else
  111.          {
  112.              SearchAndPrint(s1,s2,c,length);
  113.              return 1;
  114.          }
  115. }
  116.  
  117.  
  118. void SearchAndPrint (char s1[], char s2[], char c[],int length)
  119. {
  120.     int i,j;
  121.     char cha;
  122.  
  123.              for (i=0;i<length;i++)
  124.              {
  125.                  cha=s2[i];
  126.                  for(j=0;j<41;j++)
  127.                  {
  128.                      if(s2[j]==cha)
  129.                      {
  130.                          s2[j]=c[0];
  131.                          continue;
  132.                      }
  133.                      else
  134.                      {
  135.                          continue;
  136.                      }
  137.                  }
  138.              }
  139.              puts(s1);
  140.              puts(s2);
  141.              puts(c);
  142. }
  143.  
And im getting 3 errors like:
Expand|Select|Wrap|Line Numbers
  1. :\Temp\lab213.c(36) : error C2143: syntax error : missing ';' before 'type'
  2. I:\Temp\lab213.c(39) : error C2065: 'i' : undeclared identifier
  3. I:\Temp\lab213.c(43) : error C2065: 'n' : undeclared identifier
  4.  
Note: All the above errors are about the function
int rnd(char s1[],char s2[],char c[])
Please help!!!!!
Apr 18 '08 #1
2 1388
Laharl
849 Recognized Expert Contributor
You're missing a } to close main().

rand() returns a double. Use (char) to cast to char so it goes into your array.
Apr 18 '08 #2
Alenik1989
64 New Member
Tanx. That helped alot.
May 2 '08 #3

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

Similar topics

1
1649
by: terry | last post by:
I am a programmer (cobol, peoplesoft, sqr, etc.) so I am familiar with programming logic, etc. but not very familiar with C. I need a C program in a study I'm doing. The program is fairly simple, but not familiar with C code it would take me some time to get it to work. A good C programmer can probably give me the code in a few minutes. Here's the program specs: I'm doing a study on the italicized words in the King James Bible. The...
1
293
by: Dr_Z2A | last post by:
Ok so a couple months ago I wrote a currency converter and never got it to compile (my memorization of syntax sucked then) and I just had the printed out copy lying in a stack of papers. So I found it the other day and decided to fix it up. I have one problem that I can't figure out in it still. When I run the program it prompts for the option number as it is supposed to, but when I enter in the number it outputs that I have entered an...
66
5337
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
11
3914
by: punkybrewster | last post by:
I need to write a program that will compute a number (base) raised to a power which can be an integer, negative or zero with out including the math library. This is what I wrote thus far. Please help me. #include <iostream> using namespace std; int main() { double x, y; cout << "Enter a base number: ";
4
2767
by: asif929 | last post by:
I have another program to write, i will appreciate if somebody can help......prompts the user to enter positive integer, and then prints out four triangles For Example: If we enter 4 it should shows * * * * * * * * * *
1
1268
by: Jesika L | last post by:
I need help with a program that have to calculate the area under two curves. If anyone gave me any tips for it I will appreciate....
1
2818
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display. the...
1
947
by: Apolakkiatis | last post by:
I need help with this program i am making... it is a print screen application which takes pictures of what's going on by the sendkeys command and pressing Ctrl + Print Scr (I know kind of corny but w/e). I use VB08 and need help on how i would be able to "paste" these onto another form of my application... then be able to look through the pictures from the first to the last. Help Please...!
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
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 we have to send another system
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.