Jump to content
Sign in to follow this  
kz_syaz

String

Recommended Posts

sy orang baru dalam putera.com :rolleyes: pas tu nak tanya pasal string (c language)....boleh terangkan dengan lebih mendalam pasal string...

Share this post


Link to post
Share on other sites

kz_syaz wrote to my pm box

boleh tanya lagi???? canme nak tukarkan original code kpd encoded code guna string dlm c language?????please help me....i really need ur help :(

original code a hingga z. encoded code {r,x,b,g,t}.contoh a diwakili oleh r.b diwakili oleh x dan seterusnya.. selepas tu... paparan yang perlu dikeluarkan ilah original ang encoded....tak bawak soalan tu. tonigh sy sent kat awk soalan yang penuh...sy dah pening pale nak buat sume tu.

why the heck most of newbie forumers love to pm moderator for a direct answer?

Share this post


Link to post
Share on other sites

ok lah, soalan tu lebih kurang camni,

#include <stdio.h>
#include <string.h>

char table[] = {'r','x','b','g','t'};
void convert(char *);

int main()
{

    char* mytext="abcde";
    char* mytext2="decab";

    convert(mytext);
    printf("%s\n\n", mytext);
    convert(mytext2);
    printf("%s\n\n", mytext2);

    return 0;
}

void convert(char* text)
{
    int len = 0;
    char temp = 0;

    len = strlen(text);
    while (len > 0)
    {
        temp = *text - 0x61;
        *text = table[temp];
        *text++;
        len--;
    }
}
kalau nak nampak 'elegant' lagi
void convert(char* text)
{
    while (*text != 0)
    {
        *text = table[*text - 0x61];
        *text++;
    }
}

pandai2 la modify utk support a to z

warning: jgn pakai mingw compiler, mungkin ada masalah.

Edited by zeph

Share this post


Link to post
Share on other sites

zach... nak tanya nie... cording tu ble modifykan output apa yang dimasukkan oleh programmer... masalahnya sekarang nie cording yang nak tu ouput mesti user boleh masukkan..pas tu nak tanya... tahu tak for mula untuk tukarkan ory ke encode???? yang bagi air tu tak dapat nak tukar laa bila user tang masukkan aksara.

Share this post


Link to post
Share on other sites

awak ubah la utk accept string dari user. simple jer. kan lesson pertama awak dalam kelas/lecture C ialah meminta input dari user dan display balik input. takkan dah lupa kut.

char text[100]={0};
printf("sila masukkan text awak: ");
scanf("%s", text);
convert(text);

tang decode/encode tu, saya dah bagi cara encoding, apa kata awak perah sikit otak tu utk fikir menterbalikkan process. takde la kompleks sangat pun

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...