scanf %s

相關問題 & 資訊整理

scanf %s

以下提幾個scanf 較少見的技巧,確實不難,下面直接舉例說明。 0. 指定長度%5s. 配對時,最多只收長度為5 之字串. char s[2000],g[200]; scanf("%5s%s", s, g); printf("s=%s, g=%s-n", s, g);. 1234567890 s=12345, g=67890. 1. 指定字元配對%[abz;]. 配對時,只收abz; 這四個字元. char s[2000],g[200]; scanf(",而要在scanf 及printf 讀入及印出一個字串則是使用%s。由於C 語言中並沒有字串的變數型態,而是用字元的陣列來儲存一個字串,例如:. char s[20], t[20]="TCGS";. scanf("%s", s);. printf("%s", s);. 上面的例子宣告了s 是一個字串,長度為20 個字元。我們在宣告字串的時候要注意它的長度,以免位數不夠造成程式錯誤。事實上,每個字串 ... , 一、快速了解. 1.scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别。若想从键盘上输入字符串"hi hello",则应该使用__gets__函数。 2.gets可以接收空格,回车结束,gets(s)是输入一行;而scanf(%s)遇到空格、回车和Tab键都会认为输入结束,所有它不能接收空格。 char string[15]; gets(string); /*遇到回 ...,printf() 與scanf() 學習C 的過程中,通常是從主控台,也就是文字模式下開始,為了與程式互動,在主控台下輸出程式執行結果,或是從主控台取得使用者的輸入資料是 ... %e, %E, 使用科學記號顯示浮點數. %g, %G, 浮點數輸出,取 %f 或 %e ( %f 或 %E ),看哪個表示精簡. %%, 顯示 %. %s, 字串輸出. %lu, long unsigned 型態的整數. ,因遇到scanf("%[^-n]",s);這行看不懂的程式所以上網Google了一下結果發現他有很大的優點能解決scanf 讀取字串時碰到空白字元會提早結束的問題以下為scanf特殊寫法的介紹 scanf中不常見但有用的轉換字元[...] 和[^...] 範例程式01 #include <stdio.h> int main() char s[200]; scanf("%[abc]",s); printf("%s-n",s); ret, For printf, the * allows you to specify minimum field width through an extra parameter, i.e. printf("%*d", 4, 100); specifies a field width of 4. For scanf , the * indicates that the field is to be read but ignored, so that i.e. scanf("%*d,The two pointer values ( str and &str ) have the same binary value, namely the address of str . They do, however, have different types: When passed as an argument, str is converted to type char * , while &str has type char (*)[80] . The former is , An array "decays" into a pointer to its first element, so scanf("%s", string) is equivalent to scanf("%s", &string[0]) . On the other hand, scanf("%s", &string) passes a pointer-to- char[256] , but it point, #include <stdio.h> #include <stdlib.h> main() char name[80] , user[80] , password[80]; float height , weight; int number; printf ("請輸入姓名: "); scanf ("%s" , &name); printf ("請輸入帳號: "); scanf ("%s" ,,scanf("-n%[^x]-n",name); 輸入xyz printf("%s",name); yz scanf("-n%[^ ]-n",name); >>>>scanf 遇到空白就會認為輸入結束嚕. 會是這樣的情形 scanf("%[^-0]%*s",name); 一直叫我輸入.停不瞭 >(很多open source 的專案都用%s 代過而我都讀不出來) 請問一下.我也很想找這種東西 ope

相關軟體 Code Compare 資訊

Code Compare
Code Compare 是一個免費的工具,旨在比較和合併不同的文件和文件夾。 Code Compare 集成了所有流行的源代碼控制系統:TFS,SVN,Git,Mercurial 和 Perforce。 Code Compare 作為獨立的文件比較工具和 Visual Studio 擴展出貨。免費版 Code Compare 使開發人員能夠執行與源代碼比較相關的大部分任務。Code Compar... Code Compare 軟體介紹

scanf %s 相關參考資料
置頂[C&amp;++] scanf 進階用法 - Edison.X. Blog - 痞客邦

以下提幾個scanf 較少見的技巧,確實不難,下面直接舉例說明。 0. 指定長度%5s. 配對時,最多只收長度為5 之字串. char s[2000],g[200]; scanf(&quot;%5s%s&quot;, s, g); printf(&quot;s=%s, g=%s-n&quot;, s, g);. 1234567890 s=12345, g=67890. 1. 指定字元配對%[abz...

http://edisonx.pixnet.net

字元與字串

而要在scanf 及printf 讀入及印出一個字串則是使用%s。由於C 語言中並沒有字串的變數型態,而是用字元的陣列來儲存一個字串,例如:. char s[20], t[20]=&quot;TCGS&quot;;. scanf(&quot;%s&quot;, s);. printf(&quot;%s&quot;, s);. 上面的例子宣告了s 是一個字串,長度為20 個字元。我們在宣告字串的時候...

http://dhcp.tcgs.tc.edu.tw

字符串处理之gets与scanf(&quot;%s&quot;)的区别- CSDN博客

一、快速了解. 1.scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别。若想从键盘上输入字符串&quot;hi hello&quot;,则应该使用__gets__函数。 2.gets可以接收空格,回车结束,gets(s)是输入一行;而scanf(%s)遇到空格、回车和Tab键都会认为输入结束,所有它不能接收空格。 char string[15]; gets(string...

https://blog.csdn.net

printf() 與scanf() - OpenHome.cc

printf() 與scanf() 學習C 的過程中,通常是從主控台,也就是文字模式下開始,為了與程式互動,在主控台下輸出程式執行結果,或是從主控台取得使用者的輸入資料是 ... %e, %E, 使用科學記號顯示浮點數. %g, %G, 浮點數輸出,取 %f 或 %e ( %f 或 %E ),看哪個表示精簡. %%, 顯示 %. %s, 字串輸出. %lu, long unsigned 型態的整數...

https://openhome.cc

scanf()特殊寫法- 紅燒小站 - Google Sites

因遇到scanf(&quot;%[^-n]&quot;,s);這行看不懂的程式所以上網Google了一下結果發現他有很大的優點能解決scanf 讀取字串時碰到空白字元會提早結束的問題以下為scanf特殊寫法的介紹 scanf中不常見但有用的轉換字元[...] 和[^...] 範例程式01 #include &lt;stdio.h&gt; int main() char s[200]; scanf...

https://sites.google.com

what is scanf(&quot;%*s&quot;) and scanf(&quot;%*d&quot;) format identifiers? - Stack ...

For printf, the * allows you to specify minimum field width through an extra parameter, i.e. printf(&quot;%*d&quot;, 4, 100); specifies a field width of 4. For scanf , the * indicates that the field ...

https://stackoverflow.com

Why scanf(&quot;%s&quot;,&amp;str); behaves as scanf(&quot;%s&quot;,str) - Stack Overflow

The two pointer values ( str and &amp;str ) have the same binary value, namely the address of str . They do, however, have different types: When passed as an argument, str is converted to type char * ...

https://stackoverflow.com

c - Reading a string with scanf - Stack Overflow

An array &quot;decays&quot; into a pointer to its first element, so scanf(&quot;%s&quot;, string) is equivalent to scanf(&quot;%s&quot;, &amp;string[0]) . On the other hand, scanf(&quot;%s&quot;, &am...

https://stackoverflow.com

scanf 讓使用者自訂變數| 電腦不難

#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; main() char name[80] , user[80] , password[80]; float height , weight; int number; printf (&quot;請輸入姓名: &quot;); scanf (&quot;%s&quot; , &amp;name)...

http://it-easy.tw

scanf(%s)不可輸入空白 C++ 程式設計俱樂部

scanf(&quot;-n%[^x]-n&quot;,name); 輸入xyz printf(&quot;%s&quot;,name); yz scanf(&quot;-n%[^ ]-n&quot;,name); &gt;&gt;&gt;&gt;scanf 遇到空白就會認為輸入結束嚕. 會是這樣的情形 scanf(&quot;%[^-0]%*s&quot;,name); 一直叫我輸入.停不瞭 &...

http://programmer-club.com.tw