Tech Forums > ph.Cyberview

Anybody know C++?

<< < (2/4) > >>

renz_sui:
Ang gulo nung 5. Scanning characters from keyboard tas hindi dapat scanf or any other STDIO functions? pano yun? Assembly call?

geetar_geek79:
nde...  gagawa ka ng sariling function na mayroong array.  doon mo ii-store yung bawat letter na input sa keyboard tapos terminate mo ng null string.  ayaw kasi ng proff namin gamitin namin yung built-in function ng C++.  Gusto raw nya kami matuto gumawa ng sariling functions saka mag-manipulate ng Arrays...  hirap nga, eh.  Napaka-tnga ko pa naman sa Arrays...

Slamat boss.

sonnyrayvaughn:
hehe demm i shouldve taken C++... kung VB/VBA lang sana yan id be glad to help...

good luck bro!

renz_sui:

--- Quote from: geetar_geek79 ---nde...  gagawa ka ng sariling function na mayroong array.  doon mo ii-store yung bawat letter na input sa keyboard tapos terminate mo ng null string.  ayaw kasi ng proff namin gamitin namin yung built-in function ng C++.  Gusto raw nya kami matuto gumawa ng sariling functions saka mag-manipulate ng Arrays...  hirap nga, eh.  Napaka-tnga ko pa naman sa Arrays...

Slamat boss.
--- End quote ---


ahh simple lang yan. Try mo tong code na to.

short get_str(char[] strPrompt, char[] strFilename, long MAX)
{
short i,n;
char[] strArray;

printf("%s",strPrompt);//print prompt
scanf("%s",&strArray);//okaya gets(strArray);

for(n=0;strArray[n]!='\0';n++);//count string input length

if(strlen(strArray)<MAX)//check if input exceeds maximum no. of strings
{
    for(i=0;i<n;i++)
        strFilename=strArray;//copies the contents char per char
 
    strFilename='\0';//null pointer for string.
    return i;//return the length of string
}

else
     return -1;//return something to denote exceeding of value

}

namida:
ahh simple lang yan. Try mo tong code na to.

short get_str(char[] strPrompt, char[] strFilename, long MAX)
{
short i,n;
char[] strArray;

printf("%s",strPrompt);//print prompt
scanf("%s",&strArray);//okaya gets(strArray);

^^look out for this one. you have not allocated any space for strArray, this will lead to a very confusing debugging struggle, use fgets :D. Never use gets :D

WOA, do not use str*, that is reserverd for system use and will confuse the compiler :) kindly review standard naming conventions and rules :)


for(n=0;strArray[n]!='\0';n++);//count string input length

if(strlen(strArray)<MAX)//check if input exceeds maximum no. of strings
{
    for(i=0;i<n;i++)
        strFilename=strArray;//copies the contents char per char <-- strFilename must be big enough to hold strArray :)
 
    strFilename='\0';//null pointer for string. <-- you might overwrite the last character you copied on to the string :) i++ :D
    return i;//return the length of string
}

else
     return -1;//return something to denote exceeding of value

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version