两个函数都使用字符串,而不是单个字符。通常很方便的是从char
创建一个长度为1的新字符串,并使用该字符串:
char str[] = { t,'\0' };
现在您可以将其连接起来。
或者,您可以通过将字符写入结果数组的正确位置来手动实现串联:
const len = strlen(rez);
rez[len] = t;
rez[len + 1] = '\0';
…,或者您可以使用sprintf
函数:
sprintf(rez,"%s%c",rez,t);
在所有情况下,您都需要注意不要意外地在字符串的边界之外书写。
在您的特定情况下,这些都没有意义,因为rez
开头是空的;您不是串联任何对象,而是将单个字符写入缓冲区。
rez[0] = t;
rez[1] = '\0'; // for good measure
,
strcat
和char *
期望它们的两个参数都具有类型t
和,两个参数都指向以零结尾的字符串。
问题在于temp
和&t
都不是指针,也不是字符串的开头字符,因此传递&temp
或rez
都不会起作用。
如果要将单个字符附加到/**
* Use character literals instead of raw ASCII codes -
* it’s easier to understand,it will work as expected
* on non-ASCII systems,and you’re less likely to make
* a mistake.
*/
t = 'a';
size_t len = strlen(rez);
/**
* Overwrite the terminator with the value in t,* then write the terminator to the following element
* (strictly not necessary in this case,but it never
* hurts to make sure)
*/
rez[len++] = t;
rez[len] = 0;
,则可以执行类似的操作
sprintf
您还可以使用sprintf( rez,t );
库函数:
<script>
function popupForModifying() {
let option = "width=820,height=400,toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no";
window.open("{{ url_for('modify',content=content[2],title=content[0],category=content[4]) }}","",option);
}
</script>
<article>
<table class="table">
<thead>
<tr class="table-active">
<th class="col-8 text-left">{{ content[0] }}</th>
<th class="col-4"></th>
</tr>
<tr>
<td class="text-left">{{ content[4] }}
| {{ content[1] }}
| {{ content[3][0] }}</td>
</tr>
</thead>
<tbody>
<tr>
<td class="col-12 text-left">{{ content[2] }}</td>
<td class="col-0"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<a class="btn btn-light" href="javascript:popupForModifying()">수정하기</a>
</td>
</tr>
</tfoot>
</table>
</article>
本文链接:https://www.f2er.com/1778267.html