473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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 1363
Laharl
849 Expert 512MB
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
Tanx. That helped alot.
May 2 '08 #3

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

Similar topics

1
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,...
1
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...
66
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...
11
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...
4
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...
1
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
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.