פורסם 2013 בינואר 812 שנים מחבר פיתאום זה עובד גם עם ה int ************************ מחרוזות (שאלה פשוטה) קלוט שם ושם מישפחה וצור מחרוזת נוספת המכילה שם פרטי ושם מישפחה. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>int main(){int name[20],last_name[20],total[50];printf ("enter your name!");gets(name);printf ("enter your last name!");gets(last_name);strcpy(total,name);strcat(total, " ");strcat(total,last_name);puts (total);getch();return 0;}
פורסם 2013 בינואר 812 שנים מחבר ---עוד שאלה קלילה----קלוט מחרוזת והדפס את אורכה. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>int main(){char word[100];int str;printf ("enter a word!(up to 50 letters) :");gets(word);str=strlen (word);printf(" the len of the `word` %d\n ",str);getch();return 0;}
פורסם 2013 בינואר 812 שנים אתה חייב לבחור שמות משמעותיים יותר.המשתנה str יכול להיקרא strLength או רק length.אגב, אם כבר ++C אז תשתמש ב-()cin.get ולא ב-()getch
פורסם 2013 בינואר 812 שנים cin.get זה לא אותו דבר כמו getch... הראשון קורא תו מהbuffer והשני קורא ישירות מהמקלדת.
פורסם 2013 בינואר 912 שנים מחבר קלוט שני מחרוזות ובדוק אם הם זהות. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>#include <stdlib.h>int main(){char name[50],name_2[50];int calculus_cmp=0;printf ("enter your name!(up to 40 letters)");gets (name);printf("enter another name!(up to 40 letters)");gets (name_2);calculus_cmp= strcmp(name,name_2);if (calculus_cmp == 0){printf("the names are the same!");}elseprintf("the names are not the same!");getch();return 0;}
פורסם 2013 בינואר 912 שנים למה לשמור את הערך שמחזירה הפונקציה strcmp ולא ישר לבצע בדיקה עליו? לדוגמא:if (strcmp(name1,name2)){ printf("the names are different");}else{ printf("the names are identical");}
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.