Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1

    Default Unsay sayup sa akong code??? I need help!!!


    I am trying to reverse a string without using "strrev"...naay sayup nya ga libug jud ko

    By the way, this is TurboC


    #include <stdio.h>
    int reverse(char r);
    main ()
    {
    int i,j;
    char a[10];
    char temp;
    clrscr ();
    printf("Enter a string: ");
    gets(a);
    reverse(a[i],temp);
    getch();
    }
    int reverse(char r){
    for (i=0;a[i]!='\0';i++);
    i--;
    for (j=0;j <= i/2 ;j++)
    {
    temp = a[j];
    a[j] = a[i-j];
    a[i-j] = temp;
    }
    printf("%s",a);
    getch();

    }
    Last edited by clark; 10-08-2010 at 02:12 PM.

  2. #2
    pag.gamit nmo sa reverse function kay sayop. You have defined it with one (1) parameter but you are using it with two (2). Next ang imong parameter kay char ang naka define, but sa pag.call na sa function Array ang imong gi.pass as parameter.

    Question.
    1. required jud nga mogamit ka ug function?

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    void reverse(char str[]);
    
    void main(){
    char str_to_rev[80];
    
    clrscr();
    printf("Please enter a string: ");
    gets(str_to_rev);
    
    reverse(str);
    getch();
    }
    
    void reverse(char str[]){
    int x;
    
      for(x=strlen(str); x>=0; x--){
         printf("%c",str[x]);
      }
    }
    I don't know if sakto ba na nga code, dugay2x nako wala nakagamit ug TurboC, please nlng ko correct sa mga errors.
    Last edited by ChaosOrb; 10-08-2010 at 03:02 PM.

  3. #3
    Quote Originally Posted by clark View Post
    I am trying to reverse a string without using "strrev"...naay sayup nya ga libug jud ko

    By the way, this is TurboC


    #include <stdio.h>
    int reverse(char r);
    main ()
    {
    int i,j;
    char a[10];
    char temp;
    clrscr ();
    printf("Enter a string: ");
    gets(a);
    reverse(a[i],temp);
    getch();
    }
    int reverse(char r){
    for (i=0;a[i]!='\0';i++);
    i--;
    for (j=0;j <= i/2 ;j++)
    {
    temp = a[j];
    a[j] = a[i-j];
    a[i-j] = temp;
    }
    printf("%s",a);
    getch();

    }
    reverse(a[i],temp); <----your calling function reverse with 1 parameter, but your passing 2 arguments

  4. #4
    I'll try to edit this code with your advice

    @ChaosORb, yes sir required ko mo himo ug function
    Last edited by clark; 10-08-2010 at 04:21 PM.

  5. #5
    akong g kwaan ug function, mo gana cya....g libog jud ko unsaun ni pagbutang ug function, at least 2 functions pa jud!!!!

    #include <stdio.h>
    main ()
    {
    int i,j;
    char a[10];
    char temp;
    clrscr ();
    printf("Enter a String :");
    gets(a);
    for (i=0;a[i]!='\0';i++);
    i--;
    for (j=0;j <= i/2 ;j++)
    {
    temp = a[j];
    a[j] = a[i-j];
    a[i-j] = temp;
    }
    printf("The reversed string is : %s",a);
    getch();

    }
    Last edited by clark; 10-08-2010 at 04:57 PM.

  6. #6
    it seems that the problem is the variable that you passed sa reverse na function nimo.

    can you post here kung unsa na variables imong gipass sa reverse fnc nimo, and kung unsa ang error/output.

    also, suggestion lang: why not return the reversed string sa reverse fnc? instead of just returning an int.

    good luck!

  7. #7
    Quote Originally Posted by over[s]eer View Post
    it seems that the problem is the variable that you passed sa reverse na function nimo.

    can you post here kung unsa na variables imong gipass sa reverse fnc nimo, and kung unsa ang error/output.

    also, suggestion lang: why not return the reversed string sa reverse fnc? instead of just returning an int.

    good luck!
    ako sa ni suwayan ug usab with your advise

  8. #8
    bro mao mani among exam didto sa nec. hehehehe c usually turbo c didto, ing ni jud ang exam namo didto. hehh

  9. #9
    --------- -- - ----

  10. #10
    Dia pa kuy problema, binary to decimal ni turboc gihapun...kung mo sobra ug 5 digits ang no na i input, lahi ang mo gawas...example type in ka ug 1100100(equivalent ni sa 100 in decmal) ang output kay -52...nganu mani

    #include <stdio.h>
    #include <math.h>

    main() {
    int dec=0,flag=0;
    int bin, bit;
    double exp=0;
    clrscr();

    printf("Enter a binary number : ");
    scanf("%d", &bin);

    while(bin) {
    bit=bin%10;
    if (bit !=0 && bit !=1) {
    flag=1;
    }
    bin=bin/10;
    dec=dec+bit*pow(2, exp);
    exp++;
    }

    printf("\nNumber in decimal : %d\n", dec);

    getch();

    }

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. unsay problema sa akong motor? pls help
    By paploka in forum Automotive
    Replies: 17
    Last Post: 02-10-2013, 06:25 PM
  2. UNSAY GUBA SA AKONG HARD DISK????
    By MisterSuave in forum Computer Hardware
    Replies: 20
    Last Post: 12-11-2011, 07:19 AM
  3. masters sa simple win xp. need help asap please
    By RebC in forum Software & Games (Old)
    Replies: 22
    Last Post: 03-03-2008, 01:10 PM
  4. Question sa akong PC.... i need assistance
    By blackmiller in forum Computer Hardware
    Replies: 6
    Last Post: 01-29-2006, 05:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top